Showing
9 changed files
with
35 additions
and
131 deletions
core/api/src/main/java/org/onlab/onos/store/service/PreconditionFailedException.java
deleted
100644 → 0
| 1 | -package org.onlab.onos.store.service; | ||
| 2 | - | ||
| 3 | -/** | ||
| 4 | - * Exception that indicates a precondition failure. | ||
| 5 | - * Scenarios that can cause this exception: | ||
| 6 | - * <ul> | ||
| 7 | - * <li>An operation that attempts to write a new value iff the current value is equal | ||
| 8 | - * to some specified value.</li> | ||
| 9 | - * <li>An operation that attempts to write a new value iff the current version | ||
| 10 | - * matches a specified value</li> | ||
| 11 | - * </ul> | ||
| 12 | - */ | ||
| 13 | -@SuppressWarnings("serial") | ||
| 14 | -public class PreconditionFailedException extends DatabaseException { | ||
| 15 | -} | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | package org.onlab.onos.store.service; | 1 | package org.onlab.onos.store.service; |
| 2 | 2 | ||
| 3 | +/** | ||
| 4 | + * Status of completed read request. | ||
| 5 | + */ | ||
| 3 | public enum ReadStatus { | 6 | public enum ReadStatus { |
| 4 | - OK, | 7 | + |
| 8 | + /** | ||
| 9 | + * Read completed successfully. | ||
| 10 | + */ | ||
| 11 | + OK, | ||
| 12 | + | ||
| 13 | + /** | ||
| 14 | + * Read failed due to an invalid table name being specified. | ||
| 15 | + */ | ||
| 5 | NO_SUCH_TABLE | 16 | NO_SUCH_TABLE |
| 6 | } | 17 | } | ... | ... |
| 1 | package org.onlab.onos.store.service; | 1 | package org.onlab.onos.store.service; |
| 2 | 2 | ||
| 3 | +/** | ||
| 4 | + * Status of completed write request. | ||
| 5 | + */ | ||
| 3 | public enum WriteStatus { | 6 | public enum WriteStatus { |
| 7 | + | ||
| 8 | + /** | ||
| 9 | + * Write completed successfully. | ||
| 10 | + */ | ||
| 4 | OK, | 11 | OK, |
| 12 | + | ||
| 13 | + /** | ||
| 14 | + * Write was aborted (ex: if one or more write operations in a batch fail, others are aborted) | ||
| 15 | + */ | ||
| 5 | ABORTED, | 16 | ABORTED, |
| 17 | + | ||
| 18 | + /** | ||
| 19 | + * Write failed due to pre-condition failure. (ex: version or value mis-match) | ||
| 20 | + */ | ||
| 6 | PRECONDITION_VIOLATION, | 21 | PRECONDITION_VIOLATION, |
| 22 | + | ||
| 23 | + /** | ||
| 24 | + * Write failed due to an invalid table name being specified. | ||
| 25 | + */ | ||
| 7 | NO_SUCH_TABLE, | 26 | NO_SUCH_TABLE, |
| 8 | } | 27 | } | ... | ... |
| ... | @@ -111,16 +111,12 @@ public class ClusterMessagingProtocol | ... | @@ -111,16 +111,12 @@ public class ClusterMessagingProtocol |
| 111 | .register(ReadRequest.class) | 111 | .register(ReadRequest.class) |
| 112 | .register(WriteRequest.class) | 112 | .register(WriteRequest.class) |
| 113 | .register(WriteRequest.Type.class) | 113 | .register(WriteRequest.Type.class) |
| 114 | - .register(InternalReadResult.class) | ||
| 115 | - .register(InternalWriteResult.class) | ||
| 116 | - .register(InternalReadResult.Status.class) | ||
| 117 | .register(WriteResult.class) | 114 | .register(WriteResult.class) |
| 118 | .register(ReadResult.class) | 115 | .register(ReadResult.class) |
| 119 | .register(BatchReadRequest.class) | 116 | .register(BatchReadRequest.class) |
| 120 | .register(BatchWriteRequest.class) | 117 | .register(BatchWriteRequest.class) |
| 121 | .register(ReadStatus.class) | 118 | .register(ReadStatus.class) |
| 122 | .register(WriteStatus.class) | 119 | .register(WriteStatus.class) |
| 123 | - .register(InternalWriteResult.Status.class) | ||
| 124 | .register(VersionedValue.class) | 120 | .register(VersionedValue.class) |
| 125 | .build(); | 121 | .build(); |
| 126 | 122 | ... | ... |
| ... | @@ -11,7 +11,6 @@ import org.joda.time.DateTime; | ... | @@ -11,7 +11,6 @@ import org.joda.time.DateTime; |
| 11 | import org.onlab.onos.cluster.ClusterService; | 11 | import org.onlab.onos.cluster.ClusterService; |
| 12 | import org.onlab.onos.store.service.DatabaseService; | 12 | import org.onlab.onos.store.service.DatabaseService; |
| 13 | import org.onlab.onos.store.service.Lock; | 13 | import org.onlab.onos.store.service.Lock; |
| 14 | -import org.onlab.onos.store.service.OptimisticLockException; | ||
| 15 | 14 | ||
| 16 | /** | 15 | /** |
| 17 | * A distributed lock implementation. | 16 | * A distributed lock implementation. |
| ... | @@ -57,12 +56,10 @@ public class DistributedLock implements Lock { | ... | @@ -57,12 +56,10 @@ public class DistributedLock implements Lock { |
| 57 | 56 | ||
| 58 | @Override | 57 | @Override |
| 59 | public boolean tryLock(int leaseDurationMillis) { | 58 | public boolean tryLock(int leaseDurationMillis) { |
| 60 | - try { | 59 | + return databaseService.putIfAbsent( |
| 61 | - databaseService.putIfAbsent(DistributedLockManager.ONOS_LOCK_TABLE_NAME, path, lockId); | 60 | + DistributedLockManager.ONOS_LOCK_TABLE_NAME, |
| 62 | - return true; | 61 | + path, |
| 63 | - } catch (OptimisticLockException e) { | 62 | + lockId); |
| 64 | - return false; | ||
| 65 | - } | ||
| 66 | } | 63 | } |
| 67 | 64 | ||
| 68 | @Override | 65 | @Override | ... | ... |
core/store/dist/src/main/java/org/onlab/onos/store/service/impl/InternalReadResult.java
deleted
100644 → 0
| 1 | -package org.onlab.onos.store.service.impl; | ||
| 2 | - | ||
| 3 | -import java.io.Serializable; | ||
| 4 | - | ||
| 5 | -import org.onlab.onos.store.service.ReadResult; | ||
| 6 | - | ||
| 7 | -/** | ||
| 8 | - * Result of a read operation executed on the DatabaseStateMachine. | ||
| 9 | - */ | ||
| 10 | -@SuppressWarnings("serial") | ||
| 11 | -public class InternalReadResult implements Serializable { | ||
| 12 | - | ||
| 13 | - public enum Status { | ||
| 14 | - OK, | ||
| 15 | - NO_SUCH_TABLE | ||
| 16 | - } | ||
| 17 | - | ||
| 18 | - private final Status status; | ||
| 19 | - private final ReadResult result; | ||
| 20 | - | ||
| 21 | - public InternalReadResult(Status status, ReadResult result) { | ||
| 22 | - this.status = status; | ||
| 23 | - this.result = result; | ||
| 24 | - } | ||
| 25 | - | ||
| 26 | - public Status status() { | ||
| 27 | - return status; | ||
| 28 | - } | ||
| 29 | - | ||
| 30 | - public ReadResult result() { | ||
| 31 | - return result; | ||
| 32 | - } | ||
| 33 | - | ||
| 34 | - @Override | ||
| 35 | - public String toString() { | ||
| 36 | - return "InternalReadResult [status=" + status + ", result=" + result | ||
| 37 | - + "]"; | ||
| 38 | - } | ||
| 39 | -} | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
core/store/dist/src/main/java/org/onlab/onos/store/service/impl/InternalWriteResult.java
deleted
100644 → 0
| 1 | -package org.onlab.onos.store.service.impl; | ||
| 2 | - | ||
| 3 | -import org.onlab.onos.store.service.WriteResult; | ||
| 4 | - | ||
| 5 | -import com.google.common.base.MoreObjects; | ||
| 6 | - | ||
| 7 | -/** | ||
| 8 | - * Result of a write operation executed on the DatabaseStateMachine. | ||
| 9 | - */ | ||
| 10 | -public class InternalWriteResult { | ||
| 11 | - | ||
| 12 | - public enum Status { | ||
| 13 | - OK, | ||
| 14 | - ABORTED, | ||
| 15 | - NO_SUCH_TABLE, | ||
| 16 | - PREVIOUS_VERSION_MISMATCH, | ||
| 17 | - PREVIOUS_VALUE_MISMATCH | ||
| 18 | - } | ||
| 19 | - | ||
| 20 | - private final Status status; | ||
| 21 | - private final WriteResult result; | ||
| 22 | - | ||
| 23 | - public static InternalWriteResult ok(WriteResult result) { | ||
| 24 | - return new InternalWriteResult(Status.OK, result); | ||
| 25 | - } | ||
| 26 | - | ||
| 27 | - public InternalWriteResult(Status status, WriteResult result) { | ||
| 28 | - this.status = status; | ||
| 29 | - this.result = result; | ||
| 30 | - } | ||
| 31 | - | ||
| 32 | - public Status status() { | ||
| 33 | - return status; | ||
| 34 | - } | ||
| 35 | - | ||
| 36 | - public WriteResult result() { | ||
| 37 | - return result; | ||
| 38 | - } | ||
| 39 | - | ||
| 40 | - @Override | ||
| 41 | - public String toString() { | ||
| 42 | - return MoreObjects.toStringHelper(getClass()) | ||
| 43 | - .add("status", status) | ||
| 44 | - .add("result", result) | ||
| 45 | - .toString(); | ||
| 46 | - } | ||
| 47 | -} |
-
Please register or login to post a comment