use of org.onosproject.store.LogicalTimestamp in project onos by opennetworkinglab.
the class FlowBucket method clear.
/**
* Clears the bucket.
*/
public void clear() {
term = 0;
timestamp = new LogicalTimestamp(0);
flowBucket.clear();
}
use of org.onosproject.store.LogicalTimestamp in project onos by opennetworkinglab.
the class MapValueTest method testConstruction.
@Test
public void testConstruction() {
Timestamp ts = new LogicalTimestamp(10);
MapValue<String> mv = new MapValue<>("foo", ts);
assertEquals("foo", mv.get());
assertEquals(ts, mv.timestamp());
assertTrue(mv.isAlive());
}
use of org.onosproject.store.LogicalTimestamp in project onos by opennetworkinglab.
the class DeviceFlowTable method backupBucketToNode.
/**
* Backs up the given flow bucket to the given node.
*
* @param bucket the bucket to backup
* @param nodeId the node to which to back up the bucket
* @return a future to be completed once the bucket has been backed up
*/
private CompletableFuture<Void> backupBucketToNode(FlowBucket bucket, NodeId nodeId) {
// Record the logical timestamp from the bucket to keep track of the highest logical time replicated.
LogicalTimestamp timestamp = bucket.timestamp();
// If the backup can be run (no concurrent backup to the node in progress) then run it.
BackupOperation operation = new BackupOperation(nodeId, bucket.bucketId().bucket());
if (startBackup(operation, timestamp)) {
CompletableFuture<Void> future = new CompletableFuture<>();
backup(bucket, nodeId).whenCompleteAsync((succeeded, error) -> {
if (error != null) {
log.debug("Backup operation {} failed", operation, error);
failBackup(operation);
} else if (succeeded) {
succeedBackup(operation, timestamp);
} else {
log.debug("Backup operation {} failed: term mismatch", operation);
failBackup(operation);
}
future.complete(null);
}, executor);
return future;
}
return CompletableFuture.completedFuture(null);
}
use of org.onosproject.store.LogicalTimestamp in project onos by opennetworkinglab.
the class MapValueTest method testComparison.
@SuppressWarnings("SelfComparison")
@Test
public void testComparison() {
Timestamp ts1 = new LogicalTimestamp(9);
Timestamp ts2 = new LogicalTimestamp(10);
Timestamp ts3 = new LogicalTimestamp(11);
MapValue<String> mv1 = new MapValue<>("foo", ts1);
MapValue<String> mv2 = new MapValue<>("foo", ts2);
MapValue<String> mv3 = new MapValue<>("foo", ts3);
assertTrue(mv2.isNewerThan(mv1));
assertFalse(mv1.isNewerThan(mv3));
assertTrue(mv3.isNewerThan(ts2));
assertFalse(mv1.isNewerThan(ts2));
assertTrue(mv1.compareTo(mv2) < 0);
assertTrue(mv1.compareTo(mv1) == 0);
assertTrue(mv3.compareTo(mv2) > 0);
}
use of org.onosproject.store.LogicalTimestamp in project onos by opennetworkinglab.
the class MapValueTest method testDigest.
@Test
public void testDigest() {
Timestamp ts = new LogicalTimestamp(10);
MapValue<String> mv = new MapValue<>("foo", ts);
Digest actual = mv.digest();
Digest expected = new MapValue.Digest(ts, false);
assertEquals(actual, expected);
}
Aggregations