diff --git a/modules/core/src/main/java/org/apache/ignite/igfs/IgfsConcurrentModificationException.java b/modules/core/src/main/java/org/apache/ignite/igfs/IgfsConcurrentModificationException.java index 3c7e970..63ff70e 100644 --- a/modules/core/src/main/java/org/apache/ignite/igfs/IgfsConcurrentModificationException.java +++ b/modules/core/src/main/java/org/apache/ignite/igfs/IgfsConcurrentModificationException.java @@ -17,6 +17,8 @@ package org.apache.ignite.igfs; +import org.jetbrains.annotations.*; + /** * {@code IGFS} exception indicating that file system structure was modified concurrently. This error * indicates that an operation performed in DUAL mode cannot proceed due to these changes. @@ -26,11 +28,30 @@ public class IgfsConcurrentModificationException extends IgfsException { private static final long serialVersionUID = 0L; /** - * Creates new exception. + * Constructor. + * + * @param msg Message. + */ + public IgfsConcurrentModificationException(String msg) { + super(msg); + } + + /** + * Constructor. + * + * @param cause Cause. + */ + public IgfsConcurrentModificationException(Throwable cause) { + super(cause); + } + + /** + * Constructor. * - * @param path Affected path. + * @param msg Message. + * @param cause Cause. */ - public IgfsConcurrentModificationException(IgfsPath path) { - super("File system entry has been modified concurrently: " + path, null); + public IgfsConcurrentModificationException(@Nullable String msg, @Nullable Throwable cause) { + super(msg, cause); } } diff --git a/modules/core/src/main/java/org/apache/ignite/igfs/IgfsCorruptedFileException.java b/modules/core/src/main/java/org/apache/ignite/igfs/IgfsCorruptedFileException.java index dea19e8..c2a6fd8 100644 --- a/modules/core/src/main/java/org/apache/ignite/igfs/IgfsCorruptedFileException.java +++ b/modules/core/src/main/java/org/apache/ignite/igfs/IgfsCorruptedFileException.java @@ -27,24 +27,30 @@ public class IgfsCorruptedFileException extends IgfsException { private static final long serialVersionUID = 0L; /** - * @param msg Error message. + * Constructor. + * + * @param msg Message. */ public IgfsCorruptedFileException(String msg) { super(msg); } /** - * @param cause Error cause. + * Constructor. + * + * @param cause Cause. */ public IgfsCorruptedFileException(Throwable cause) { super(cause); } /** - * @param msg Error message. - * @param cause Error cause. + * Constructor. + * + * @param msg Message. + * @param cause Cause. */ - public IgfsCorruptedFileException(String msg, @Nullable Throwable cause) { + public IgfsCorruptedFileException(@Nullable String msg, @Nullable Throwable cause) { super(msg, cause); } } diff --git a/modules/core/src/main/java/org/apache/ignite/igfs/IgfsDirectoryNotEmptyException.java b/modules/core/src/main/java/org/apache/ignite/igfs/IgfsDirectoryNotEmptyException.java index 38a7eaf..2df6faa 100644 --- a/modules/core/src/main/java/org/apache/ignite/igfs/IgfsDirectoryNotEmptyException.java +++ b/modules/core/src/main/java/org/apache/ignite/igfs/IgfsDirectoryNotEmptyException.java @@ -17,6 +17,8 @@ package org.apache.ignite.igfs; +import org.jetbrains.annotations.*; + /** * Exception indicating that directory can not be deleted because it is not empty. */ @@ -25,18 +27,30 @@ public class IgfsDirectoryNotEmptyException extends IgfsException { private static final long serialVersionUID = 0L; /** - * @param msg Exception message. + * Constructor. + * + * @param msg Message. */ public IgfsDirectoryNotEmptyException(String msg) { super(msg); } /** - * Creates an instance of IGFS exception caused by nested exception. + * Constructor. * - * @param cause Exception cause. + * @param cause Cause. */ public IgfsDirectoryNotEmptyException(Throwable cause) { super(cause); } + + /** + * Constructor. + * + * @param msg Message. + * @param cause Cause. + */ + public IgfsDirectoryNotEmptyException(@Nullable String msg, @Nullable Throwable cause) { + super(msg, cause); + } } diff --git a/modules/core/src/main/java/org/apache/ignite/igfs/IgfsException.java b/modules/core/src/main/java/org/apache/ignite/igfs/IgfsException.java index a704fe8..630be38 100644 --- a/modules/core/src/main/java/org/apache/ignite/igfs/IgfsException.java +++ b/modules/core/src/main/java/org/apache/ignite/igfs/IgfsException.java @@ -28,30 +28,30 @@ public class IgfsException extends IgniteException { private static final long serialVersionUID = 0L; /** - * Creates an instance of IGFS exception with descriptive error message. + * Constructor. * - * @param msg Error message. + * @param msg Message. */ public IgfsException(String msg) { super(msg); } /** - * Creates an instance of IGFS exception caused by nested exception. + * Constructor. * - * @param cause Exception cause. + * @param cause Cause. */ public IgfsException(Throwable cause) { super(cause); } /** - * Creates an instance of IGFS exception with error message and underlying cause. + * Constructor. * - * @param msg Error message. - * @param cause Exception cause. + * @param msg Message. + * @param cause Cause. */ - public IgfsException(String msg, @Nullable Throwable cause) { + public IgfsException(@Nullable String msg, @Nullable Throwable cause) { super(msg, cause); } } diff --git a/modules/core/src/main/java/org/apache/ignite/igfs/IgfsInvalidHdfsVersionException.java b/modules/core/src/main/java/org/apache/ignite/igfs/IgfsInvalidHdfsVersionException.java index 4375d47..4b4a72e 100644 --- a/modules/core/src/main/java/org/apache/ignite/igfs/IgfsInvalidHdfsVersionException.java +++ b/modules/core/src/main/java/org/apache/ignite/igfs/IgfsInvalidHdfsVersionException.java @@ -17,6 +17,8 @@ package org.apache.ignite.igfs; +import org.jetbrains.annotations.*; + /** * Exception thrown when Ignite detects that remote HDFS version differs from version of HDFS libraries * in Ignite classpath. @@ -26,17 +28,30 @@ public class IgfsInvalidHdfsVersionException extends IgfsException { private static final long serialVersionUID = 0L; /** - * @param msg Error message. + * Constructor. + * + * @param msg Message. */ public IgfsInvalidHdfsVersionException(String msg) { super(msg); } /** - * @param msg Error message. - * @param cause Error cause. + * Constructor. + * + * @param cause Cause. + */ + public IgfsInvalidHdfsVersionException(Throwable cause) { + super(cause); + } + + /** + * Constructor. + * + * @param msg Message. + * @param cause Cause. */ - public IgfsInvalidHdfsVersionException(String msg, Throwable cause) { + public IgfsInvalidHdfsVersionException(@Nullable String msg, @Nullable Throwable cause) { super(msg, cause); } } diff --git a/modules/core/src/main/java/org/apache/ignite/igfs/IgfsInvalidPathException.java b/modules/core/src/main/java/org/apache/ignite/igfs/IgfsInvalidPathException.java index bb7b5da..8049afe 100644 --- a/modules/core/src/main/java/org/apache/ignite/igfs/IgfsInvalidPathException.java +++ b/modules/core/src/main/java/org/apache/ignite/igfs/IgfsInvalidPathException.java @@ -28,30 +28,30 @@ public class IgfsInvalidPathException extends IgfsException { private static final long serialVersionUID = 0L; /** - * Creates exception with given error message. + * Constructor. * - * @param msg Error message. + * @param msg Message. */ public IgfsInvalidPathException(String msg) { super(msg); } /** - * Creates exception with given exception cause. + * Constructor. * - * @param cause Exception cause. + * @param cause Cause. */ public IgfsInvalidPathException(Throwable cause) { super(cause); } /** - * Creates exception with given error message and exception cause. + * Constructor. * - * @param msg Error message. - * @param cause Error cause. + * @param msg Message. + * @param cause Cause. */ - public IgfsInvalidPathException(String msg, @Nullable Throwable cause) { + public IgfsInvalidPathException(@Nullable String msg, @Nullable Throwable cause) { super(msg, cause); } } diff --git a/modules/core/src/main/java/org/apache/ignite/igfs/IgfsOutOfSpaceException.java b/modules/core/src/main/java/org/apache/ignite/igfs/IgfsOutOfSpaceException.java index a4fd60e..029afff 100644 --- a/modules/core/src/main/java/org/apache/ignite/igfs/IgfsOutOfSpaceException.java +++ b/modules/core/src/main/java/org/apache/ignite/igfs/IgfsOutOfSpaceException.java @@ -29,30 +29,30 @@ public class IgfsOutOfSpaceException extends IgfsException { private static final long serialVersionUID = 0L; /** - * Creates exception with given error message. + * Constructor. * - * @param msg Error message. + * @param msg Message. */ public IgfsOutOfSpaceException(String msg) { super(msg); } /** - * Creates an instance of exception with given exception cause. + * Constructor. * - * @param cause Exception cause. + * @param cause Cause. */ public IgfsOutOfSpaceException(Throwable cause) { super(cause); } /** - * Creates an instance of IGFS exception with given error message and given exception cause. + * Constructor. * - * @param msg Error message. - * @param cause Exception cause. + * @param msg Message. + * @param cause Cause. */ - public IgfsOutOfSpaceException(String msg, @Nullable Throwable cause) { + public IgfsOutOfSpaceException(@Nullable String msg, @Nullable Throwable cause) { super(msg, cause); } } diff --git a/modules/core/src/main/java/org/apache/ignite/igfs/IgfsParentNotDirectoryException.java b/modules/core/src/main/java/org/apache/ignite/igfs/IgfsParentNotDirectoryException.java index 62d8887..c2e4eca 100644 --- a/modules/core/src/main/java/org/apache/ignite/igfs/IgfsParentNotDirectoryException.java +++ b/modules/core/src/main/java/org/apache/ignite/igfs/IgfsParentNotDirectoryException.java @@ -22,29 +22,35 @@ import org.jetbrains.annotations.*; /** * Exception thrown when parent supposed to be a directory is a file. */ -public class IgfsParentNotDirectoryException extends IgfsInvalidPathException { +public class IgfsParentNotDirectoryException extends IgfsException { /** */ private static final long serialVersionUID = 0L; /** - * @param msg Error message. + * Constructor. + * + * @param msg Message. */ public IgfsParentNotDirectoryException(String msg) { super(msg); } /** - * @param cause Exception cause. + * Constructor. + * + * @param cause Cause. */ public IgfsParentNotDirectoryException(Throwable cause) { super(cause); } /** - * @param msg Error message. - * @param cause Exception cause. + * Constructor. + * + * @param msg Message. + * @param cause Cause. */ - public IgfsParentNotDirectoryException(String msg, @Nullable Throwable cause) { + public IgfsParentNotDirectoryException(@Nullable String msg, @Nullable Throwable cause) { super(msg, cause); } -} +} \ No newline at end of file diff --git a/modules/core/src/main/java/org/apache/ignite/igfs/IgfsPathAlreadyExistsException.java b/modules/core/src/main/java/org/apache/ignite/igfs/IgfsPathAlreadyExistsException.java index ca8b8a1..939f6ba 100644 --- a/modules/core/src/main/java/org/apache/ignite/igfs/IgfsPathAlreadyExistsException.java +++ b/modules/core/src/main/java/org/apache/ignite/igfs/IgfsPathAlreadyExistsException.java @@ -17,34 +17,41 @@ package org.apache.ignite.igfs; +import org.apache.ignite.internal.processors.igfs.*; import org.jetbrains.annotations.*; /** * Exception thrown when target path supposed to be created already exists. */ -public class IgfsPathAlreadyExistsException extends IgfsInvalidPathException { +public class IgfsPathAlreadyExistsException extends IgfsException { /** */ private static final long serialVersionUID = 0L; /** - * @param msg Error message. + * Constructor. + * + * @param msg Message. */ public IgfsPathAlreadyExistsException(String msg) { super(msg); } /** - * @param cause Exception cause. + * Constructor. + * + * @param cause Cause. */ public IgfsPathAlreadyExistsException(Throwable cause) { super(cause); } /** - * @param msg Error message. - * @param cause Exception cause. + * Constructor. + * + * @param msg Message. + * @param cause Cause. */ - public IgfsPathAlreadyExistsException(String msg, @Nullable Throwable cause) { + public IgfsPathAlreadyExistsException(@Nullable String msg, @Nullable Throwable cause) { super(msg, cause); } } diff --git a/modules/core/src/main/java/org/apache/ignite/igfs/IgfsPathIsDirectoryException.java b/modules/core/src/main/java/org/apache/ignite/igfs/IgfsPathIsDirectoryException.java new file mode 100644 index 0000000..4892ee8 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/igfs/IgfsPathIsDirectoryException.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.igfs; + +import org.jetbrains.annotations.*; + +/** + * Exception indicating that path is directory, while it is expected to be a file. + */ +public class IgfsPathIsDirectoryException extends IgfsException { + /** */ + private static final long serialVersionUID = 0L; + + /** + * Constructor. + * + * @param msg Message. + */ + public IgfsPathIsDirectoryException(String msg) { + super(msg); + } + + /** + * Constructor. + * + * @param cause Cause. + */ + public IgfsPathIsDirectoryException(Throwable cause) { + super(cause); + } + + /** + * Constructor. + * + * @param msg Message. + * @param cause Cause. + */ + public IgfsPathIsDirectoryException(@Nullable String msg, @Nullable Throwable cause) { + super(msg, cause); + } +} diff --git a/modules/core/src/main/java/org/apache/ignite/igfs/IgfsPathIsNotDirectoryException.java b/modules/core/src/main/java/org/apache/ignite/igfs/IgfsPathIsNotDirectoryException.java new file mode 100644 index 0000000..d4b5ff9 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/igfs/IgfsPathIsNotDirectoryException.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.igfs; + +import org.jetbrains.annotations.*; + +/** + * Exception indicating that path is not directory. + */ +public class IgfsPathIsNotDirectoryException extends IgfsException { + /** */ + private static final long serialVersionUID = 0L; + + /** + * Constructor. + * + * @param msg Message. + */ + public IgfsPathIsNotDirectoryException(String msg) { + super(msg); + } + + /** + * Constructor. + * + * @param cause Cause. + */ + public IgfsPathIsNotDirectoryException(Throwable cause) { + super(cause); + } + + /** + * Constructor. + * + * @param msg Message. + * @param cause Cause. + */ + public IgfsPathIsNotDirectoryException(@Nullable String msg, @Nullable Throwable cause) { + super(msg, cause); + } +} diff --git a/modules/core/src/main/java/org/apache/ignite/igfs/IgfsPathNotFoundException.java b/modules/core/src/main/java/org/apache/ignite/igfs/IgfsPathNotFoundException.java index 1f6a6ad..4172be7 100644 --- a/modules/core/src/main/java/org/apache/ignite/igfs/IgfsPathNotFoundException.java +++ b/modules/core/src/main/java/org/apache/ignite/igfs/IgfsPathNotFoundException.java @@ -17,28 +17,40 @@ package org.apache.ignite.igfs; +import org.jetbrains.annotations.*; + /** * {@code IGFS} exception indicating that target resource is not found. */ -public class IgfsPathNotFoundException extends IgfsInvalidPathException { +public class IgfsPathNotFoundException extends IgfsException { /** */ private static final long serialVersionUID = 0L; /** - * Creates exception with error message specified. + * Constructor. * - * @param msg Error message. + * @param msg Message. */ public IgfsPathNotFoundException(String msg) { super(msg); } /** - * Creates exception with given exception cause. + * Constructor. * - * @param cause Exception cause. + * @param cause Cause. */ public IgfsPathNotFoundException(Throwable cause) { super(cause); } + + /** + * Constructor. + * + * @param msg Message. + * @param cause Cause. + */ + public IgfsPathNotFoundException(@Nullable String msg, @Nullable Throwable cause) { + super(msg, cause); + } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsImpl.java index 9ccb2a9..8e45b71 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsImpl.java @@ -44,6 +44,7 @@ import org.jetbrains.annotations.*; import java.io.*; import java.net.*; import java.util.*; +import java.util.concurrent.*; import java.util.concurrent.atomic.*; import static org.apache.ignite.events.EventType.*; @@ -309,8 +310,8 @@ public final class IgfsImpl implements IgfsEx { } } else - throw new IgniteCheckedException("Cannot create new output stream to the secondary file system because IGFS is " + - "stopping: " + path); + throw new IllegalStateException("Cannot create new output stream to the secondary file system " + + "because IGFS is stopping: " + path); } /** @@ -400,25 +401,20 @@ public final class IgfsImpl implements IgfsEx { /** {@inheritDoc} */ @SuppressWarnings("ConstantConditions") @Override public IgfsStatus globalSpace() { - if (enterBusy()) { - try { + return safeOp(new Callable() { + @Override public IgfsStatus call() throws Exception { IgniteBiTuple space = igfsCtx.kernalContext().grid().compute().execute( new IgfsGlobalSpaceTask(name()), null); return new IgfsStatus(space.get1(), space.get2()); } - finally { - busyLock.leaveBusy(); - } - } - else - throw new IllegalStateException("Failed to get global space because Grid is stopping."); + }); } /** {@inheritDoc} */ - @Override public void globalSampling(@Nullable Boolean val) throws IgniteCheckedException { - if (enterBusy()) { - try { + @Override public void globalSampling(@Nullable final Boolean val) throws IgniteCheckedException { + safeOp(new Callable() { + @Override public Void call() throws Exception { if (meta.sampling(val)) { if (val == null) log.info("Sampling flag has been cleared. All further file system connections will perform " + @@ -430,34 +426,19 @@ public final class IgfsImpl implements IgfsEx { log.info("Sampling flag has been set to \"false\". All further file system connections will " + "not perform logging."); } + + return null; } - finally { - busyLock.leaveBusy(); - } - } - else - throw new IllegalStateException("Failed to set global sampling flag because Grid is stopping."); + }); } /** {@inheritDoc} */ @Override @Nullable public Boolean globalSampling() { - if (enterBusy()) { - try { - try { - return meta.sampling(); - } - catch (IgniteCheckedException e) { - U.error(log, "Failed to get sampling state.", e); - - return false; - } + return safeOp(new Callable() { + @Override public Boolean call() throws Exception { + return meta.sampling(); } - finally { - busyLock.leaveBusy(); - } - } - else - throw new IllegalStateException("Failed to get global sampling flag because Grid is stopping."); + }); } /** {@inheritDoc} */ @@ -471,59 +452,52 @@ public final class IgfsImpl implements IgfsEx { } /** {@inheritDoc} */ - @Override public boolean exists(IgfsPath path) { - try { - A.notNull(path, "path"); + @Override public boolean exists(final IgfsPath path) { + A.notNull(path, "path"); - if (log.isDebugEnabled()) - log.debug("Check file exists: " + path); + return safeOp(new Callable() { + @Override public Boolean call() throws Exception { + if (log.isDebugEnabled()) + log.debug("Check file exists: " + path); - IgfsMode mode = modeRslvr.resolveMode(path); + IgfsMode mode = resolveMode(path); - if (mode == PROXY) - throw new IgniteException("PROXY mode cannot be used in IGFS directly: " + path); + boolean res = false; - boolean res = false; + switch (mode) { + case PRIMARY: + res = meta.fileId(path) != null; - switch (mode) { - case PRIMARY: - res = meta.fileId(path) != null; + break; - break; + case DUAL_SYNC: + case DUAL_ASYNC: + res = meta.fileId(path) != null; - case DUAL_SYNC: - case DUAL_ASYNC: - res = meta.fileId(path) != null; + if (!res) + res = secondaryFs.exists(path); - if (!res) - res = secondaryFs.exists(path); + break; - break; + default: + assert false : "Unknown mode."; + } - default: - assert false : "Unknown mode."; + return res; } - - return res; - } - catch (IgniteCheckedException e) { - throw U.convertException(e); - } + }); } /** {@inheritDoc} */ - @Override public IgfsFile info(IgfsPath path) { - if (enterBusy()) { - try { - A.notNull(path, "path"); + @Override public IgfsFile info(final IgfsPath path) { + A.notNull(path, "path"); + return safeOp(new Callable() { + @Override public IgfsFile call() throws Exception { if (log.isDebugEnabled()) log.debug("Get file info: " + path); - IgfsMode mode = modeRslvr.resolveMode(path); - - if (mode == PROXY) - throw new IgniteException("PROXY mode cannot be used in IGFS directly: " + path); + IgfsMode mode = resolveMode(path); IgfsFileInfo info = resolveFileInfo(path, mode); @@ -532,23 +506,15 @@ public final class IgfsImpl implements IgfsEx { return new IgfsFileImpl(path, info, data.groupBlockSize()); } - catch (IgniteCheckedException e) { - throw U.convertException(e); - } - finally { - busyLock.leaveBusy(); - } - } - else - throw new IllegalStateException("Failed to get path info because grid is stopping."); + }); } /** {@inheritDoc} */ - @Override public IgfsPathSummary summary(IgfsPath path) { - if (enterBusy()) { - try { - A.notNull(path, "path"); + @Override public IgfsPathSummary summary(final IgfsPath path) { + A.notNull(path, "path"); + return safeOp(new Callable() { + @Override public IgfsPathSummary call() throws Exception { if (log.isDebugEnabled()) log.debug("Calculating path summary: " + path); @@ -563,33 +529,23 @@ public final class IgfsImpl implements IgfsEx { return sum; } - catch (IgniteCheckedException e) { - throw U.convertException(e); - } - finally { - busyLock.leaveBusy(); - } - } - else - throw new IllegalStateException("Failed to get path summary because Grid is stopping."); + }); } /** {@inheritDoc} */ - @Override public IgfsFile update(IgfsPath path, Map props) { - if (enterBusy()) { - try { - A.notNull(path, "path"); - A.notNull(props, "props"); - A.ensure(!props.isEmpty(), "!props.isEmpty()"); + @Override public IgfsFile update(final IgfsPath path, final Map props) { + A.notNull(path, "path"); + A.notNull(props, "props"); + A.ensure(!props.isEmpty(), "!props.isEmpty()"); + return safeOp(new Callable() { + @Override public IgfsFile call() throws Exception { if (log.isDebugEnabled()) log.debug("Set file properties [path=" + path + ", props=" + props + ']'); - IgfsMode mode = modeRslvr.resolveMode(path); + IgfsMode mode = resolveMode(path); - if (mode == PROXY) - throw new IgniteException("PROXY mode cannot be used in IGFS directly: " + path); - else if (mode != PRIMARY) { + if (mode != PRIMARY) { assert mode == DUAL_SYNC || mode == DUAL_ASYNC; await(path); @@ -622,39 +578,29 @@ public final class IgfsImpl implements IgfsEx { else return null; } - catch (IgniteCheckedException e) { - throw U.convertException(e); - } - finally { - busyLock.leaveBusy(); - } - } - else - throw new IllegalStateException("Failed to update file because Grid is stopping."); + }); } /** {@inheritDoc} */ - @Override public void rename(IgfsPath src, IgfsPath dest) { - if (enterBusy()) { - try { - A.notNull(src, "src"); - A.notNull(dest, "dest"); + @Override public void rename(final IgfsPath src, final IgfsPath dest) { + A.notNull(src, "src"); + A.notNull(dest, "dest"); + safeOp(new Callable() { + @Override public Void call() throws Exception { if (log.isDebugEnabled()) log.debug("Rename file [src=" + src + ", dest=" + dest + ']'); - IgfsMode mode = modeRslvr.resolveMode(src); - Set childrenModes = modeRslvr.resolveChildrenModes(src); + IgfsMode mode = resolveMode(src); - if (mode == PROXY) - throw new IgniteException("PROXY mode cannot be used in IGFS directly: " + src); + Set childrenModes = modeRslvr.resolveChildrenModes(src); if (src.equals(dest)) - return; // Rename to itself is a no-op. + return null; // Rename to itself is a no-op. // Cannot rename root directory. if (src.parent() == null) - throw new IgfsInvalidPathException("Failed to rename root directory."); + throw new IgfsInvalidPathException("Root directory cannot be renamed."); // Cannot move directory of upper level to self sub-dir. if (dest.isSubDirectoryOf(src)) @@ -672,7 +618,7 @@ public final class IgfsImpl implements IgfsEx { meta.renameDual(secondaryFs, src, dest); - return; + return null; } IgfsPath destParent = dest.parent(); @@ -733,32 +679,24 @@ public final class IgfsImpl implements IgfsEx { if (evts.isRecordable(EVT_IGFS_DIR_RENAMED)) evts.record(new IgfsEvent(src, dest, localNode(), EVT_IGFS_DIR_RENAMED)); } + + return null; } - catch (IgniteCheckedException e) { - throw U.convertException(e); - } - finally { - busyLock.leaveBusy(); - } - } - else - throw new IllegalStateException("Failed to set rename path because Grid is stopping."); + }); } /** {@inheritDoc} */ - @Override public boolean delete(IgfsPath path, boolean recursive) { - if (enterBusy()) { - try { - A.notNull(path, "path"); + @Override public boolean delete(final IgfsPath path, final boolean recursive) { + A.notNull(path, "path"); + return safeOp(new Callable() { + @Override public Boolean call() throws Exception { if (log.isDebugEnabled()) log.debug("Deleting file [path=" + path + ", recursive=" + recursive + ']'); - IgfsMode mode = modeRslvr.resolveMode(path); - Set childrenModes = modeRslvr.resolveChildrenModes(path); + IgfsMode mode = resolveMode(path); - if (mode == PROXY) - throw new IgniteException("PROXY mode cannot be used in IGFS directly: " + path); + Set childrenModes = modeRslvr.resolveChildrenModes(path); boolean res = false; @@ -791,15 +729,7 @@ public final class IgfsImpl implements IgfsEx { return res; } - catch (IgniteCheckedException e) { - throw U.convertException(e); - } - finally { - busyLock.leaveBusy(); - } - } - else - throw new IllegalStateException("Failed to set file times because Grid is stopping."); + }); } /** @@ -850,29 +780,26 @@ public final class IgfsImpl implements IgfsEx { } /** {@inheritDoc} */ - @Override public void mkdirs(IgfsPath path, @Nullable Map props) { - if (enterBusy()) { - try { - A.notNull(path, "path"); + @Override public void mkdirs(final IgfsPath path, @Nullable final Map props) { + A.notNull(path, "path"); + safeOp(new Callable() { + @Override public Void call() throws Exception { if (log.isDebugEnabled()) log.debug("Make directories: " + path); - if (props == null) - props = DFLT_DIR_META; + Map props0 = props == null ? DFLT_DIR_META : props; - IgfsMode mode = modeRslvr.resolveMode(path); + IgfsMode mode = resolveMode(path); - if (mode == PROXY) - throw new IgniteException("PROXY mode cannot be used in IGFS directly: " + path); - else if (mode != PRIMARY) { + if (mode != PRIMARY) { assert mode == DUAL_SYNC || mode == DUAL_ASYNC; await(path); - meta.mkdirsDual(secondaryFs, path, props); + meta.mkdirsDual(secondaryFs, path, props0); - return; + return null; } List ids = meta.fileIds(path); @@ -889,7 +816,7 @@ public final class IgfsImpl implements IgfsEx { IgniteUuid fileId = ids.get(step + 1); // Skip the first ROOT element. if (fileId == null) { - IgfsFileInfo fileInfo = new IgfsFileInfo(true, props); // Create new directory. + IgfsFileInfo fileInfo = new IgfsFileInfo(true, props0); // Create new directory. String fileName = components.get(step); // Get current component name. @@ -913,7 +840,7 @@ public final class IgfsImpl implements IgfsEx { IgfsFileInfo stored = meta.info(meta.fileId(parentId, fileName)); if (stored == null) - throw new IgfsException(e); + throw e; if (!stored.isDirectory()) throw new IgfsParentNotDirectoryException("Failed to create directory (parent " + @@ -927,32 +854,23 @@ public final class IgfsImpl implements IgfsEx { parentId = fileId; } + + return null; } - catch (IgniteCheckedException e) { - throw U.convertException(e); - } - finally { - busyLock.leaveBusy(); - } - } - else - throw new IllegalStateException("Failed to set file times because Grid is stopping."); + }); } /** {@inheritDoc} */ @SuppressWarnings("unchecked") @Override public Collection listPaths(final IgfsPath path) { - if (enterBusy()) { - try { - A.notNull(path, "path"); + A.notNull(path, "path"); + return safeOp(new Callable>() { + @Override public Collection call() throws Exception { if (log.isDebugEnabled()) log.debug("List directory: " + path); - IgfsMode mode = modeRslvr.resolveMode(path); - - if (mode == PROXY) - throw new IgniteException("PROXY mode cannot be used in IGFS directly: " + path); + IgfsMode mode = resolveMode(path); Set childrenModes = modeRslvr.resolveChildrenModes(path); @@ -978,35 +896,25 @@ public final class IgfsImpl implements IgfsEx { } return F.viewReadOnly(files, new C1() { - @Override public IgfsPath apply(String e) { + @Override + public IgfsPath apply(String e) { return new IgfsPath(path, e); } }); } - catch (IgniteCheckedException e) { - throw U.convertException(e); - } - finally { - busyLock.leaveBusy(); - } - } - else - throw new IllegalStateException("Failed to set file times because Grid is stopping."); + }); } /** {@inheritDoc} */ @Override public Collection listFiles(final IgfsPath path) { - if (enterBusy()) { - try { - A.notNull(path, "path"); + A.notNull(path, "path"); + return safeOp(new Callable>() { + @Override public Collection call() throws Exception { if (log.isDebugEnabled()) log.debug("List directory details: " + path); - IgfsMode mode = modeRslvr.resolveMode(path); - - if (mode == PROXY) - throw new IgniteException("PROXY mode cannot be used in IGFS directly: " + path); + IgfsMode mode = resolveMode(path); Set childrenModes = modeRslvr.resolveChildrenModes(path); @@ -1053,15 +961,7 @@ public final class IgfsImpl implements IgfsEx { return files; } - catch (IgniteCheckedException e) { - throw U.convertException(e); - } - finally { - busyLock.leaveBusy(); - } - } - else - throw new IllegalStateException("Failed to set file times because Grid is stopping."); + }); } /** {@inheritDoc} */ @@ -1080,27 +980,25 @@ public final class IgfsImpl implements IgfsEx { } /** {@inheritDoc} */ - @Override public IgfsInputStreamAdapter open(IgfsPath path, int bufSize, int seqReadsBeforePrefetch) { - if (enterBusy()) { - try { - A.notNull(path, "path"); - A.ensure(bufSize >= 0, "bufSize >= 0"); - A.ensure(seqReadsBeforePrefetch >= 0, "seqReadsBeforePrefetch >= 0"); - + @Override public IgfsInputStreamAdapter open(final IgfsPath path, final int bufSize, + final int seqReadsBeforePrefetch) { + A.notNull(path, "path"); + A.ensure(bufSize >= 0, "bufSize >= 0"); + A.ensure(seqReadsBeforePrefetch >= 0, "seqReadsBeforePrefetch >= 0"); + + return safeOp(new Callable() { + @Override public IgfsInputStreamAdapter call() throws Exception { if (log.isDebugEnabled()) log.debug("Open file for reading [path=" + path + ", bufSize=" + bufSize + ']'); - if (bufSize == 0) - bufSize = cfg.getStreamBufferSize(); + int bufSize0 = bufSize == 0 ? cfg.getStreamBufferSize() : bufSize; - IgfsMode mode = modeRslvr.resolveMode(path); + IgfsMode mode = resolveMode(path); - if (mode == PROXY) - throw new IgniteException("PROXY mode cannot be used in IGFS directly: " + path); - else if (mode != PRIMARY) { + if (mode != PRIMARY) { assert mode == DUAL_SYNC || mode == DUAL_ASYNC; - IgfsSecondaryInputStreamDescriptor desc = meta.openDual(secondaryFs, path, bufSize); + IgfsSecondaryInputStreamDescriptor desc = meta.openDual(secondaryFs, path, bufSize0); IgfsEventAwareInputStream os = new IgfsEventAwareInputStream(igfsCtx, path, desc.info(), cfg.getPrefetchBlocks(), seqReadsBeforePrefetch, desc.reader(), metrics); @@ -1120,7 +1018,7 @@ public final class IgfsImpl implements IgfsEx { } if (!info.isFile()) - throw new IgfsInvalidPathException("Failed to open file (not a file): " + path); + throw new IgfsPathIsDirectoryException("Failed to open file (not a file): " + path); // Input stream to read data from grid cache with separate blocks. IgfsEventAwareInputStream os = new IgfsEventAwareInputStream(igfsCtx, path, info, @@ -1131,15 +1029,7 @@ public final class IgfsImpl implements IgfsEx { return os; } - catch (IgniteCheckedException e) { - throw U.convertException(e); - } - finally { - busyLock.leaveBusy(); - } - } - else - throw new IllegalStateException("Failed to open file because Grid is stopping."); + }); } /** {@inheritDoc} */ @@ -1175,27 +1065,25 @@ public final class IgfsImpl implements IgfsEx { final IgfsPath path, final int bufSize, final boolean overwrite, - @Nullable IgniteUuid affKey, + @Nullable final IgniteUuid affKey, final int replication, - @Nullable Map props, + @Nullable final Map props, final boolean simpleCreate ) { - if (enterBusy()) { - try { - A.notNull(path, "path"); - A.ensure(bufSize >= 0, "bufSize >= 0"); + A.notNull(path, "path"); + A.ensure(bufSize >= 0, "bufSize >= 0"); + return safeOp(new Callable() { + @Override public IgfsOutputStream call() throws Exception { if (log.isDebugEnabled()) log.debug("Open file for writing [path=" + path + ", bufSize=" + bufSize + ", overwrite=" + overwrite + ", props=" + props + ']'); - IgfsMode mode = modeRslvr.resolveMode(path); + IgfsMode mode = resolveMode(path); IgfsFileWorkerBatch batch; - if (mode == PROXY) - throw new IgniteException("PROXY mode cannot be used in IGFS directly: " + path); - else if (mode != PRIMARY) { + if (mode != PRIMARY) { assert mode == DUAL_SYNC || mode == DUAL_ASYNC; await(path); @@ -1227,13 +1115,12 @@ public final class IgfsImpl implements IgfsEx { IgniteUuid parentId = ids.size() >= 2 ? ids.get(ids.size() - 2) : null; if (parentId == null) - throw new IgfsInvalidPathException("Failed to resolve parent directory: " + path); + throw new IgfsPathNotFoundException("Failed to resolve parent directory: " + parent); String fileName = path.name(); // Constructs new file info. - IgfsFileInfo info = new IgfsFileInfo(cfg.getBlockSize(), affKey, evictExclude(path, true), - props); + IgfsFileInfo info = new IgfsFileInfo(cfg.getBlockSize(), affKey, evictExclude(path, true), props); // Add new file into tree structure. while (true) { @@ -1275,15 +1162,7 @@ public final class IgfsImpl implements IgfsEx { return os; } - catch (IgniteCheckedException e) { - throw U.convertException(e); - } - finally { - busyLock.leaveBusy(); - } - } - else - throw new IllegalStateException("Failed to create file times because Grid is stopping."); + }); } /** {@inheritDoc} */ @@ -1292,24 +1171,22 @@ public final class IgfsImpl implements IgfsEx { } /** {@inheritDoc} */ - @Override public IgfsOutputStream append(final IgfsPath path, final int bufSize, boolean create, - @Nullable Map props) { - if (enterBusy()) { - try { - A.notNull(path, "path"); - A.ensure(bufSize >= 0, "bufSize >= 0"); + @Override public IgfsOutputStream append(final IgfsPath path, final int bufSize, final boolean create, + @Nullable final Map props) { + A.notNull(path, "path"); + A.ensure(bufSize >= 0, "bufSize >= 0"); + return safeOp(new Callable() { + @Override public IgfsOutputStream call() throws Exception { if (log.isDebugEnabled()) log.debug("Open file for appending [path=" + path + ", bufSize=" + bufSize + ", create=" + create + ", props=" + props + ']'); - IgfsMode mode = modeRslvr.resolveMode(path); + IgfsMode mode = resolveMode(path); - IgfsFileWorkerBatch batch = null; + IgfsFileWorkerBatch batch; - if (mode == PROXY) - throw new IgniteException("PROXY mode cannot be used in IGFS directly: " + path); - else if (mode != PRIMARY) { + if (mode != PRIMARY) { assert mode == DUAL_SYNC || mode == DUAL_ASYNC; await(path); @@ -1337,7 +1214,7 @@ public final class IgfsImpl implements IgfsEx { } if (parentId == null) - throw new IgfsInvalidPathException("Failed to resolve parent directory: " + path); + throw new IgfsPathNotFoundException("Failed to resolve parent directory: " + path.parent()); info = new IgfsFileInfo(cfg.getBlockSize(), /**affinity key*/null, evictExclude(path, true), props); @@ -1353,7 +1230,7 @@ public final class IgfsImpl implements IgfsEx { assert info != null; if (!info.isFile()) - throw new IgfsInvalidPathException("Failed to open file (not a file): " + path); + throw new IgfsPathIsDirectoryException("Failed to open file (not a file): " + path); info = meta.lock(info.id()); @@ -1361,27 +1238,19 @@ public final class IgfsImpl implements IgfsEx { evts.record(new IgfsEvent(path, localNode(), EVT_IGFS_FILE_OPENED_WRITE)); return new IgfsEventAwareOutputStream(path, info, parentId, bufSize == 0 ? - cfg.getStreamBufferSize() : bufSize, mode, batch); + cfg.getStreamBufferSize() : bufSize, mode, null); } - catch (IgniteCheckedException e) { - throw U.convertException(e); - } - finally { - busyLock.leaveBusy(); - } - } - else - throw new IllegalStateException("Failed to append file times because Grid is stopping."); + }); } /** {@inheritDoc} */ - @Override public void setTimes(IgfsPath path, long accessTime, long modificationTime) { - if (enterBusy()) { - try { - A.notNull(path, "path"); + @Override public void setTimes(final IgfsPath path, final long accessTime, final long modificationTime) { + A.notNull(path, "path"); + safeOp(new Callable() { + @Override public Void call() throws Exception { if (accessTime == -1 && modificationTime == -1) - return; + return null; FileDescriptor desc = getFileDescriptor(path); @@ -1393,19 +1262,13 @@ public final class IgfsImpl implements IgfsEx { // Cannot update times for root. if (desc.parentId == null) - return; + return null; meta.updateTimes(desc.parentId, desc.fileId, desc.fileName, accessTime, modificationTime); + + return null; } - catch (IgniteCheckedException e) { - throw U.convertException(e); - } - finally { - busyLock.leaveBusy(); - } - } - else - throw new IllegalStateException("Failed to set file times because Grid is stopping."); + }); } /** @@ -1417,7 +1280,7 @@ public final class IgfsImpl implements IgfsEx { private void checkConflictWithPrimary(IgfsPath path) throws IgniteCheckedException { if (secondaryFs != null) { if (secondaryFs.info(path) != null) { - throw new IgniteCheckedException("Path mapped to a PRIMARY mode found in secondary file " + + throw new IgfsInvalidPathException("Path mapped to a PRIMARY mode found in secondary file " + "system. Remove path from secondary file system or change path mapping: " + path); } } @@ -1429,20 +1292,18 @@ public final class IgfsImpl implements IgfsEx { } /** {@inheritDoc} */ - @Override public Collection affinity(IgfsPath path, long start, long len, long maxLen) { - if (enterBusy()) { - try { - A.notNull(path, "path"); - A.ensure(start >= 0, "start >= 0"); - A.ensure(len >= 0, "len >= 0"); - + @Override public Collection affinity(final IgfsPath path, final long start, final long len, + final long maxLen) { + A.notNull(path, "path"); + A.ensure(start >= 0, "start >= 0"); + A.ensure(len >= 0, "len >= 0"); + + return safeOp(new Callable>() { + @Override public Collection call() throws Exception { if (log.isDebugEnabled()) log.debug("Get affinity for file block [path=" + path + ", start=" + start + ", len=" + len + ']'); - IgfsMode mode = modeRslvr.resolveMode(path); - - if (mode == PROXY) - throw new IgniteException("PROXY mode cannot be used in IGFS directly: " + path); + IgfsMode mode = resolveMode(path); // Check memory first. IgniteUuid fileId = meta.fileId(path); @@ -1460,26 +1321,18 @@ public final class IgfsImpl implements IgfsEx { throw new IgfsPathNotFoundException("File not found: " + path); if (!info.isFile()) - throw new IgfsInvalidPathException("Failed to get affinity info for file (not a file): " + - path); + throw new IgfsPathIsDirectoryException("Failed to get affinity for path because it is not " + + "a file: " + path); return data.affinity(info, start, len, maxLen); } - catch (IgniteCheckedException e) { - throw U.convertException(e); - } - finally { - busyLock.leaveBusy(); - } - } - else - throw new IllegalStateException("Failed to get affinity because Grid is stopping."); + }); } /** {@inheritDoc} */ @Override public IgfsMetrics metrics() { - if (enterBusy()) { - try { + return safeOp(new Callable() { + @Override public IgfsMetrics call() throws Exception { IgfsPathSummary sum = new IgfsPathSummary(); summary0(ROOT_ID, sum); @@ -1514,15 +1367,7 @@ public final class IgfsImpl implements IgfsEx { metrics.writeBytes(), metrics.writeBytesTime()); } - catch (IgniteCheckedException e) { - throw U.convertException(e); - } - finally { - busyLock.leaveBusy(); - } - } - else - throw new IllegalStateException("Failed to get metrics because Grid is stopping."); + }); } /** {@inheritDoc} */ @@ -1531,15 +1376,15 @@ public final class IgfsImpl implements IgfsEx { } /** {@inheritDoc} */ - @Override public long size(IgfsPath path) { - if (enterBusy()) { - try { - A.notNull(path, "path"); + @Override public long size(final IgfsPath path) { + A.notNull(path, "path"); + return safeOp(new Callable() { + @Override public Long call() throws Exception { IgniteUuid nextId = meta.fileId(path); if (nextId == null) - return 0; + return 0L; IgfsPathSummary sum = new IgfsPathSummary(path); @@ -1547,15 +1392,7 @@ public final class IgfsImpl implements IgfsEx { return sum.totalLength(); } - catch (IgniteCheckedException e) { - throw U.convertException(e); - } - finally { - busyLock.leaveBusy(); - } - } - else - throw new IllegalStateException("Failed to get path size because Grid is stopping."); + }); } /** @@ -1590,8 +1427,8 @@ public final class IgfsImpl implements IgfsEx { try { formatAsync().get(); } - catch (IgniteCheckedException e) { - throw U.convertException(e); + catch (Exception e) { + throw IgfsUtils.toIgfsException(e); } } @@ -1734,8 +1571,8 @@ public final class IgfsImpl implements IgfsEx { try { return executeAsync(task, rslvr, paths, arg).get(); } - catch (IgniteCheckedException e) { - throw U.convertException(e); + catch (Exception e) { + throw IgfsUtils.toIgfsException(e); } } @@ -1745,8 +1582,8 @@ public final class IgfsImpl implements IgfsEx { try { return executeAsync(task, rslvr, paths, skipNonExistentFiles, maxRangeLen, arg).get(); } - catch (IgniteCheckedException e) { - throw U.convertException(e); + catch (Exception e) { + throw IgfsUtils.toIgfsException(e); } } @@ -1756,8 +1593,8 @@ public final class IgfsImpl implements IgfsEx { try { return executeAsync(taskCls, rslvr, paths, arg).get(); } - catch (IgniteCheckedException e) { - throw U.convertException(e); + catch (Exception e) { + throw IgfsUtils.toIgfsException(e); } } @@ -1768,8 +1605,8 @@ public final class IgfsImpl implements IgfsEx { try { return executeAsync(taskCls, rslvr, paths, skipNonExistentFiles, maxRangeSize, arg).get(); } - catch (IgniteCheckedException e) { - throw U.convertException(e); + catch (Exception e) { + throw IgfsUtils.toIgfsException(e); } } @@ -2203,16 +2040,11 @@ public final class IgfsImpl implements IgfsEx { /** {@inheritDoc} */ @Override public IgniteUuid nextAffinityKey() { - if (enterBusy()) { - try { + return safeOp(new Callable() { + @Override public IgniteUuid call() throws Exception { return data.nextAffinityKey(null); } - finally { - busyLock.leaveBusy(); - } - } - else - throw new IllegalStateException("Failed to get next affinity key because Grid is stopping."); + }); } /** {@inheritDoc} */ @@ -2227,4 +2059,41 @@ public final class IgfsImpl implements IgfsEx { @Override public IgfsSecondaryFileSystem asSecondary() { return new IgfsSecondaryFileSystemImpl(this); } + + /** + * Resolve mode for the given path. + * + * @param path Path. + * @return Mode. + */ + private IgfsMode resolveMode(IgfsPath path) { + IgfsMode mode = modeRslvr.resolveMode(path); + + if (mode == PROXY) + throw new IgfsInvalidPathException("PROXY mode cannot be used in IGFS directly: " + path); + + return mode; + } + + /** + * Perform IGFS operation in safe context. + * + * @param action Action. + * @return Result. + */ + private T safeOp(Callable action) { + if (enterBusy()) { + try { + return action.call(); + } + catch (Exception e) { + throw IgfsUtils.toIgfsException(e); + } + finally { + busyLock.leaveBusy(); + } + } + else + throw new IllegalStateException("Failed to perform IGFS action because grid is stopping."); + } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsMetaManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsMetaManager.java index d340089..2ad10d5 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsMetaManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsMetaManager.java @@ -742,7 +742,7 @@ public class IgfsMetaManager extends IgfsManager { throw fsException(new IgfsPathNotFoundException("Failed to lock parent directory (not found): " + parentId)); if (!parentInfo.isDirectory()) - throw fsException(new IgfsInvalidPathException("Parent file is not a directory: " + parentInfo)); + throw fsException(new IgfsPathIsNotDirectoryException("Parent file is not a directory: " + parentInfo)); Map parentListing = parentInfo.listing(); @@ -843,7 +843,7 @@ public class IgfsMetaManager extends IgfsManager { " [srcParentId=" + srcParentId + ']')); if (!srcInfo.isDirectory()) - throw fsException(new IgfsInvalidPathException("Source is not a directory: " + srcInfo)); + throw fsException(new IgfsPathIsNotDirectoryException("Source is not a directory: " + srcInfo)); IgfsFileInfo destInfo = infoMap.get(destParentId); @@ -852,7 +852,7 @@ public class IgfsMetaManager extends IgfsManager { " [destParentId=" + destParentId + ']')); if (!destInfo.isDirectory()) - throw fsException(new IgfsInvalidPathException("Destination is not a directory: " + destInfo)); + throw fsException(new IgfsPathIsNotDirectoryException("Destination is not a directory: " + destInfo)); IgfsFileInfo fileInfo = infoMap.get(fileId); @@ -871,8 +871,8 @@ public class IgfsMetaManager extends IgfsManager { // If stored file already exist. if (destEntry != null) - throw fsException(new IgfsInvalidPathException("Failed to add file name into the destination directory " + - "(file already exists) [fileId=" + fileId + ", destFileName=" + destFileName + + throw fsException(new IgfsPathAlreadyExistsException("Failed to add file name into the destination " + + " directory (file already exists) [fileId=" + fileId + ", destFileName=" + destFileName + ", destParentId=" + destParentId + ", destEntry=" + destEntry + ']')); assert metaCache.get(srcParentId) != null; @@ -1846,7 +1846,8 @@ public class IgfsMetaManager extends IgfsManager { if (info != null) { if (!info.isFile()) - throw fsException(new IgfsInvalidPathException("Failed to open file (not a file): " + path)); + throw fsException(new IgfsPathIsDirectoryException("Failed to open file (not a file): " + + path)); return new IgfsSecondaryInputStreamDescriptor(info, fs.open(path, bufSize)); } @@ -1861,7 +1862,8 @@ public class IgfsMetaManager extends IgfsManager { if (info == null) throw fsException(new IgfsPathNotFoundException("File not found: " + path)); if (!info.isFile()) - throw fsException(new IgfsInvalidPathException("Failed to open file (not a file): " + path)); + throw fsException(new IgfsPathIsDirectoryException("Failed to open file " + + "(not a file): " + path)); return new IgfsSecondaryInputStreamDescriptor(infos.get(path), fs.open(path, bufSize)); } @@ -2452,7 +2454,8 @@ public class IgfsMetaManager extends IgfsManager { if (changed != null) { finished = true; - throw fsException(new IgfsConcurrentModificationException(changed)); + throw fsException(new IgfsConcurrentModificationException("File system entry has been " + + "modified concurrently: " + changed)); } else { boolean newParents = false; @@ -2616,14 +2619,14 @@ public class IgfsMetaManager extends IgfsManager { IgfsFileInfo parentInfo = infoMap.get(parentId); if (parentInfo == null) - throw fsException(new IgfsInvalidPathException("Failed to update times " + - "(parent was not found): " + fileName)); + throw fsException(new IgfsPathNotFoundException("Failed to update times " + + "(parent was not found): " + fileName)); IgfsListingEntry entry = parentInfo.listing().get(fileName); // Validate listing. if (entry == null || !entry.fileId().equals(fileId)) - throw fsException(new IgfsInvalidPathException("Failed to update times " + + throw fsException(new IgfsConcurrentModificationException("Failed to update times " + "(file concurrently modified): " + fileName)); assert parentInfo.isDirectory(); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsUtils.java new file mode 100644 index 0000000..2a915ec --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsUtils.java @@ -0,0 +1,86 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.processors.igfs; + +import org.apache.ignite.*; +import org.apache.ignite.igfs.*; +import org.apache.ignite.internal.util.typedef.*; + +import java.lang.reflect.*; + +/** + * Common IGFS utility methods. + */ +public class IgfsUtils { + /** + * Converts any passed exception to IGFS exception. + * + * @param err Initial exception. + * @return Converted IGFS exception. + */ + @SuppressWarnings("ThrowableResultOfMethodCallIgnored") + public static IgfsException toIgfsException(Exception err) { + IgfsException err0 = err instanceof IgfsException ? (IgfsException)err : null; + + IgfsException igfsErr = X.cause(err, IgfsException.class); + + while (igfsErr != null && igfsErr != err0) { + err0 = igfsErr; + + igfsErr = X.cause(err, IgfsException.class); + } + + // If initial exception is already IGFS exception and no inner stuff exists, just return it unchanged. + if (err0 != err) { + if (err0 != null) + // Dealing with a kind of IGFS error, wrap it once again, preserving message and root cause. + err0 = newIgfsException(err0.getClass(), err0.getMessage(), err0); + else + // Unknown error nature. + err0 = new IgfsException("Generic IGFS error occurred.", err); + } + + return err0; + } + + /** + * Construct new IGFS exception passing specified message and cause. + * + * @param cls Class. + * @param msg Message. + * @param cause Cause. + * @return New IGFS exception. + */ + public static IgfsException newIgfsException(Class cls, String msg, Throwable cause) { + try { + Constructor ctor = cls.getConstructor(String.class, Throwable.class); + + return ctor.newInstance(msg, cause); + } + catch (ReflectiveOperationException e) { + throw new IgniteException("Failed to create IGFS exception: " + cls.getName(), e); + } + } + + /** + * Constructor. + */ + private IgfsUtils() { + // No-op. + } +} diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsAbstractSelfTest.java index c6eabde..9dde005 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsAbstractSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsAbstractSelfTest.java @@ -47,6 +47,7 @@ import static org.apache.ignite.internal.processors.igfs.IgfsEx.*; /** * Test fo regular igfs operations. */ +@SuppressWarnings("ThrowableResultOfMethodCallIgnored") public abstract class IgfsAbstractSelfTest extends IgfsCommonAbstractTest { /** IGFS block size. */ protected static final int IGFS_BLOCK_SIZE = 512 * 1024; @@ -692,25 +693,14 @@ public abstract class IgfsAbstractSelfTest extends IgfsCommonAbstractTest { public void testDeleteDirectoryNotEmpty() throws Exception { create(igfs, paths(DIR, SUBDIR, SUBSUBDIR), paths(FILE)); - // We have different results for dual and non-dual modes. - if (dual) - GridTestUtils.assertThrows(log, new Callable() { - @Override public Object call() throws Exception { - igfs.delete(SUBDIR, false); - - return null; - } - }, IgniteCheckedException.class, "Failed to delete the path due to secondary file system exception:"); - else { - GridTestUtils.assertThrows(log, new Callable() { - @Override public Object call() throws Exception { - igfs.delete(SUBDIR, false); + GridTestUtils.assertThrows(log, new Callable() { + @Override public Object call() throws Exception { + igfs.delete(SUBDIR, false); - return null; - } - }, IgfsDirectoryNotEmptyException.class, "Failed to remove directory (directory is not empty and " + - "recursive flag is not set)"); - } + return null; + } + }, IgfsDirectoryNotEmptyException.class, "Failed to remove directory (directory is not empty and " + + "recursive flag is not set)"); checkExist(igfs, igfsSecondary, SUBDIR, SUBSUBDIR, FILE); } @@ -1911,6 +1901,7 @@ public abstract class IgfsAbstractSelfTest extends IgfsCommonAbstractTest { * @param createCnt How many file creations to perform. * @throws Exception If failed. */ + @SuppressWarnings("ConstantConditions") public void checkDeadlocks(final int lvlCnt, final int childrenDirPerLvl, final int childrenFilePerLvl, int primaryLvlCnt, int renCnt, int delCnt, int updateCnt, int mkdirsCnt, int createCnt) throws Exception { @@ -2444,14 +2435,14 @@ public abstract class IgfsAbstractSelfTest extends IgfsCommonAbstractTest { * @param igfs IGFS. * @throws Exception If failed. */ + @SuppressWarnings("unchecked") public static void clear(IgniteFileSystem igfs) throws Exception { Field workerMapFld = IgfsImpl.class.getDeclaredField("workerMap"); workerMapFld.setAccessible(true); // Wait for all workers to finish. - Map workerMap = - (Map)workerMapFld.get(igfs); + Map workerMap = (Map)workerMapFld.get(igfs); for (Map.Entry entry : workerMap.entrySet()) { entry.getValue().cancel(); diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteIgfsTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteIgfsTestSuite.java index cea510a..e67e661 100644 --- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteIgfsTestSuite.java +++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteIgfsTestSuite.java @@ -58,6 +58,8 @@ public class IgniteIgfsTestSuite extends TestSuite { suite.addTest(new TestSuite(IgfsPrimarySelfTest.class)); suite.addTest(new TestSuite(IgfsPrimaryOffheapTieredSelfTest.class)); suite.addTest(new TestSuite(IgfsPrimaryOffheapValuesSelfTest.class)); + suite.addTest(new TestSuite(IgfsDualSyncSelfTest.class)); + suite.addTest(new TestSuite(IgfsDualAsyncSelfTest.class)); suite.addTest(new TestSuite(IgfsModeResolverSelfTest.class));