Search in sources :

Example 1 with LogicalTimestamp

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();
}
Also used : LogicalTimestamp(org.onosproject.store.LogicalTimestamp)

Example 2 with LogicalTimestamp

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());
}
Also used : LogicalTimestamp(org.onosproject.store.LogicalTimestamp) Timestamp(org.onosproject.store.Timestamp) LogicalTimestamp(org.onosproject.store.LogicalTimestamp) Test(org.junit.Test)

Example 3 with LogicalTimestamp

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);
}
Also used : LogicalTimestamp(org.onosproject.store.LogicalTimestamp) CompletableFuture(java.util.concurrent.CompletableFuture)

Example 4 with LogicalTimestamp

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);
}
Also used : LogicalTimestamp(org.onosproject.store.LogicalTimestamp) Timestamp(org.onosproject.store.Timestamp) LogicalTimestamp(org.onosproject.store.LogicalTimestamp) Test(org.junit.Test)

Example 5 with LogicalTimestamp

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);
}
Also used : LogicalTimestamp(org.onosproject.store.LogicalTimestamp) Digest(org.onosproject.store.atomix.primitives.impl.MapValue.Digest) Timestamp(org.onosproject.store.Timestamp) LogicalTimestamp(org.onosproject.store.LogicalTimestamp) Test(org.junit.Test)

Aggregations

LogicalTimestamp (org.onosproject.store.LogicalTimestamp)6 Test (org.junit.Test)4 Timestamp (org.onosproject.store.Timestamp)4 CompletableFuture (java.util.concurrent.CompletableFuture)1 Digest (org.onosproject.store.atomix.primitives.impl.MapValue.Digest)1