本文整理汇总了Java中org.apache.cassandra.utils.FBUtilities.timestampMicros方法的典型用法代码示例。如果您正苦于以下问题:Java FBUtilities.timestampMicros方法的具体用法?Java FBUtilities.timestampMicros怎么用?Java FBUtilities.timestampMicros使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.cassandra.utils.FBUtilities
的用法示例。
在下文中一共展示了FBUtilities.timestampMicros方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: saveSystemKeyspacesSchema
import org.apache.cassandra.utils.FBUtilities; //导入方法依赖的package包/类
/**
* Add entries to system_schema.* for the hardcoded system keyspaces
*/
public static void saveSystemKeyspacesSchema()
{
KeyspaceMetadata system = Schema.instance.getKSMetaData(SystemKeyspace.NAME);
KeyspaceMetadata schema = Schema.instance.getKSMetaData(NAME);
long timestamp = FBUtilities.timestampMicros();
// delete old, possibly obsolete entries in schema tables
for (String schemaTable : ALL)
{
String query = String.format("DELETE FROM %s.%s USING TIMESTAMP ? WHERE keyspace_name = ?", NAME, schemaTable);
for (String systemKeyspace : Schema.SYSTEM_KEYSPACE_NAMES)
executeOnceInternal(query, timestamp, systemKeyspace);
}
// (+1 to timestamp to make sure we don't get shadowed by the tombstones we just added)
makeCreateKeyspaceMutation(system, timestamp + 1).apply();
makeCreateKeyspaceMutation(schema, timestamp + 1).apply();
}
示例2: testSerializer
import org.apache.cassandra.utils.FBUtilities; //导入方法依赖的package包/类
@Test
public void testSerializer() throws IOException
{
long now = FBUtilities.timestampMicros();
Mutation mutation = createMutation("testSerializer", now);
Hint hint = Hint.create(mutation, now / 1000);
// serialize
int serializedSize = (int) Hint.serializer.serializedSize(hint, MessagingService.current_version);
DataOutputBuffer dob = new DataOutputBuffer();
Hint.serializer.serialize(hint, dob, MessagingService.current_version);
assertEquals(serializedSize, dob.getLength());
// deserialize
DataInputPlus di = new DataInputBuffer(dob.buffer(), true);
Hint deserializedHint = Hint.serializer.deserialize(di, MessagingService.current_version);
// compare before/after
assertHintsEqual(hint, deserializedHint);
}
示例3: testApply
import org.apache.cassandra.utils.FBUtilities; //导入方法依赖的package包/类
@Test
public void testApply()
{
long now = FBUtilities.timestampMicros();
String key = "testApply";
Mutation mutation = createMutation(key, now);
Hint hint = Hint.create(mutation, now / 1000);
// sanity check that there is no data inside yet
assertNoPartitions(key, TABLE0);
assertNoPartitions(key, TABLE1);
assertNoPartitions(key, TABLE2);
hint.apply();
// assert that we can read the inserted partitions
for (PartitionUpdate partition : mutation.getPartitionUpdates())
assertPartitionsEqual(partition, readPartition(key, partition.metadata().cfName));
}
示例4: testApplyWithTruncation
import org.apache.cassandra.utils.FBUtilities; //导入方法依赖的package包/类
@Test
public void testApplyWithTruncation()
{
long now = FBUtilities.timestampMicros();
String key = "testApplyWithTruncation";
Mutation mutation = createMutation(key, now);
// sanity check that there is no data inside yet
assertNoPartitions(key, TABLE0);
assertNoPartitions(key, TABLE1);
assertNoPartitions(key, TABLE2);
// truncate TABLE1
Keyspace.open(KEYSPACE).getColumnFamilyStore(TABLE1).truncateBlocking();
// create and apply a hint with creation time in the past (one second before the truncation)
Hint.create(mutation, now / 1000 - 1).apply();
// TABLE1 update should have been skipped and not applied, as expired
assertNoPartitions(key, TABLE1);
// TABLE0 and TABLE2 updates should have been applied successfully
assertPartitionsEqual(mutation.getPartitionUpdate(Schema.instance.getId(KEYSPACE, TABLE0)), readPartition(key, TABLE0));
assertPartitionsEqual(mutation.getPartitionUpdate(Schema.instance.getId(KEYSPACE, TABLE2)), readPartition(key, TABLE2));
}
示例5: testApplyWithRegularExpiration
import org.apache.cassandra.utils.FBUtilities; //导入方法依赖的package包/类
@Test
public void testApplyWithRegularExpiration()
{
long now = FBUtilities.timestampMicros();
String key = "testApplyWithRegularExpiration";
Mutation mutation = createMutation(key, now);
// sanity check that there is no data inside yet
assertNoPartitions(key, TABLE0);
assertNoPartitions(key, TABLE1);
assertNoPartitions(key, TABLE2);
// lower the GC GS on TABLE0 to 0 BEFORE the hint is created
Schema.instance.getCFMetaData(KEYSPACE, TABLE0).gcGraceSeconds(0);
Hint.create(mutation, now / 1000).apply();
// all updates should have been skipped and not applied, as expired
assertNoPartitions(key, TABLE0);
assertNoPartitions(key, TABLE1);
assertNoPartitions(key, TABLE2);
}
示例6: testAddListEntry
import org.apache.cassandra.utils.FBUtilities; //导入方法依赖的package包/类
public void testAddListEntry(boolean skipCommitLog) throws Throwable
{
createTable("CREATE TABLE %s ("
+ "pk text,"
+ "ck text,"
+ "l1 list<int>,"
+ "l2 list<int>,"
+ "PRIMARY KEY ((pk), ck))");
long timestamp = FBUtilities.timestampMicros();
Mutation mutation = new Mutation(keyspace(), Util.dk("test"));
addToMutation("row1", timestamp, mutation);
addToMutation("row2", timestamp, mutation);
if (skipCommitLog)
mutation.applyUnsafe();
else
mutation.apply();
assertRowCount(execute("SELECT ck FROM %s"), 2);
}
示例7: augment
import org.apache.cassandra.utils.FBUtilities; //导入方法依赖的package包/类
public Collection<Mutation> augment(Partition partition)
{
RowUpdateBuilder update = new RowUpdateBuilder(partition.metadata(), FBUtilities.timestampMicros(), partition.partitionKey().getKey());
update.add("v2", 999);
return Collections.singletonList(update.build());
}
示例8: testCounterDeletion
import org.apache.cassandra.utils.FBUtilities; //导入方法依赖的package包/类
@Test
public void testCounterDeletion()
{
long timestamp = FBUtilities.timestampMicros();
CellName name = cellname("counter1");
BufferCounterCell counter = new BufferCounterCell(name,
CounterContext.instance().createGlobal(CounterId.fromInt(1), 1, 1),
timestamp);
BufferDeletedCell tombstone = new BufferDeletedCell(name, (int) (System.currentTimeMillis() / 1000), 0L);
// check that the tombstone won the reconcile despite the counter cell having a higher timestamp
assertTrue(counter.reconcile(tombstone) == tombstone);
// check that a range tombstone overrides the counter cell, even with a lower timestamp than the counter
ColumnFamily cf0 = ArrayBackedSortedColumns.factory.create("Keyspace1", "Counter1");
cf0.addColumn(counter);
cf0.delete(new RangeTombstone(cellname("counter0"), cellname("counter2"), 0L, (int) (System.currentTimeMillis() / 1000)));
assertTrue(cf0.deletionInfo().isDeleted(counter));
assertTrue(cf0.deletionInfo().inOrderTester(false).isDeleted(counter));
// check that a top-level deletion info overrides the counter cell, even with a lower timestamp than the counter
ColumnFamily cf1 = ArrayBackedSortedColumns.factory.create("Keyspace1", "Counter1");
cf1.addColumn(counter);
cf1.delete(new DeletionInfo(0L, (int) (System.currentTimeMillis() / 1000)));
assertTrue(cf1.deletionInfo().isDeleted(counter));
}
示例9: makeCf
import org.apache.cassandra.utils.FBUtilities; //导入方法依赖的package包/类
private static PartitionUpdate makeCf(CFMetaData metadata, String key, String columnValue1, String columnValue2)
{
Row.Builder builder = BTreeRow.unsortedBuilder(FBUtilities.nowInSeconds());
builder.newRow(Clustering.EMPTY);
long ts = FBUtilities.timestampMicros();
if (columnValue1 != null)
builder.addCell(BufferCell.live(metadata, metadata.getColumnDefinition(bytes("c1")), ts, bytes(columnValue1)));
if (columnValue2 != null)
builder.addCell(BufferCell.live(metadata, metadata.getColumnDefinition(bytes("c2")), ts, bytes(columnValue2)));
return PartitionUpdate.singleRowUpdate(metadata, Util.dk(key), builder.build());
}
示例10: augment
import org.apache.cassandra.utils.FBUtilities; //导入方法依赖的package包/类
public Collection<Mutation> augment(Partition update)
{
String auditKeyspace = properties.getProperty("keyspace");
String auditTable = properties.getProperty("table");
RowUpdateBuilder audit = new RowUpdateBuilder(Schema.instance.getCFMetaData(auditKeyspace, auditTable),
FBUtilities.timestampMicros(),
UUIDGen.getTimeUUID());
audit.add("keyspace_name", update.metadata().ksName);
audit.add("table_name", update.metadata().cfName);
audit.add("primary_key", update.metadata().getKeyValidator().getString(update.partitionKey().getKey()));
return Collections.singletonList(audit.build());
}
示例11: augment
import org.apache.cassandra.utils.FBUtilities; //导入方法依赖的package包/类
public Collection<Mutation> augment(Partition partition)
{
if (!partition.partitionKey().getKey().equals(bytes("k2")))
return null;
RowUpdateBuilder builder = new RowUpdateBuilder(partition.metadata(), FBUtilities.timestampMicros(), partition.partitionKey().getKey());
builder.add("c2", bytes("trigger"));
return Collections.singletonList(builder.build());
}
示例12: testIndexHelper
import org.apache.cassandra.utils.FBUtilities; //导入方法依赖的package包/类
@Test
public void testIndexHelper()
{
DeletionTime deletionInfo = new DeletionTime(FBUtilities.timestampMicros(), FBUtilities.nowInSeconds());
List<IndexInfo> indexes = new ArrayList<>();
indexes.add(new IndexInfo(cn(0L), cn(5L), 0, 0, deletionInfo));
indexes.add(new IndexInfo(cn(10L), cn(15L), 0, 0, deletionInfo));
indexes.add(new IndexInfo(cn(20L), cn(25L), 0, 0, deletionInfo));
assertEquals(0, IndexHelper.indexFor(cn(-1L), indexes, comp, false, -1));
assertEquals(0, IndexHelper.indexFor(cn(5L), indexes, comp, false, -1));
assertEquals(1, IndexHelper.indexFor(cn(12L), indexes, comp, false, -1));
assertEquals(2, IndexHelper.indexFor(cn(17L), indexes, comp, false, -1));
assertEquals(3, IndexHelper.indexFor(cn(100L), indexes, comp, false, -1));
assertEquals(3, IndexHelper.indexFor(cn(100L), indexes, comp, false, 0));
assertEquals(3, IndexHelper.indexFor(cn(100L), indexes, comp, false, 1));
assertEquals(3, IndexHelper.indexFor(cn(100L), indexes, comp, false, 2));
assertEquals(3, IndexHelper.indexFor(cn(100L), indexes, comp, false, 3));
assertEquals(-1, IndexHelper.indexFor(cn(-1L), indexes, comp, true, -1));
assertEquals(0, IndexHelper.indexFor(cn(5L), indexes, comp, true, 3));
assertEquals(0, IndexHelper.indexFor(cn(5L), indexes, comp, true, 2));
assertEquals(1, IndexHelper.indexFor(cn(17L), indexes, comp, true, 3));
assertEquals(2, IndexHelper.indexFor(cn(100L), indexes, comp, true, 3));
assertEquals(2, IndexHelper.indexFor(cn(100L), indexes, comp, true, 4));
assertEquals(1, IndexHelper.indexFor(cn(12L), indexes, comp, true, 3));
assertEquals(1, IndexHelper.indexFor(cn(12L), indexes, comp, true, 2));
assertEquals(1, IndexHelper.indexFor(cn(100L), indexes, comp, true, 1));
assertEquals(2, IndexHelper.indexFor(cn(100L), indexes, comp, true, 2));
}
示例13: testCommittingAfterTruncation
import org.apache.cassandra.utils.FBUtilities; //导入方法依赖的package包/类
@Test
public void testCommittingAfterTruncation() throws Exception
{
ColumnFamilyStore cfs = Keyspace.open("PaxosStateTestKeyspace1").getColumnFamilyStore("Standard1");
String key = "key" + System.nanoTime();
ByteBuffer value = ByteBufferUtil.bytes(0);
RowUpdateBuilder builder = new RowUpdateBuilder(cfs.metadata, FBUtilities.timestampMicros(), key);
builder.clustering("a").add("val", value);
PartitionUpdate update = Iterables.getOnlyElement(builder.build().getPartitionUpdates());
// CFS should be empty initially
assertNoDataPresent(cfs, Util.dk(key));
// Commit the proposal & verify the data is present
Commit beforeTruncate = newProposal(0, update);
PaxosState.commit(beforeTruncate);
assertDataPresent(cfs, Util.dk(key), "val", value);
// Truncate then attempt to commit again, mutation should
// be ignored as the proposal predates the truncation
cfs.truncateBlocking();
PaxosState.commit(beforeTruncate);
assertNoDataPresent(cfs, Util.dk(key));
// Now try again with a ballot created after the truncation
long timestamp = SystemKeyspace.getTruncatedAt(update.metadata().cfId) + 1;
Commit afterTruncate = newProposal(timestamp, update);
PaxosState.commit(afterTruncate);
assertDataPresent(cfs, Util.dk(key), "val", value);
}
示例14: testGetFullyExpiredSSTables
import org.apache.cassandra.utils.FBUtilities; //导入方法依赖的package包/类
@Test
public void testGetFullyExpiredSSTables()
{
Keyspace keyspace = Keyspace.open(KEYSPACE);
ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(CF2);
cfs.truncateBlocking();
DecoratedKey key = Util.dk("k1");
long timestamp1 = FBUtilities.timestampMicros(); // latest timestamp
long timestamp2 = timestamp1 - 5;
long timestamp3 = timestamp2 - 5; // oldest timestamp
// create sstable with tombstone that should be expired in no older timestamps
applyDeleteMutation(cfs.metadata, key, timestamp2);
cfs.forceBlockingFlush();
// first sstable with tombstone is compacting
Set<SSTableReader> compacting = Sets.newHashSet(cfs.getLiveSSTables());
// create another sstable with more recent timestamp
applyMutation(cfs.metadata, key, timestamp1);
cfs.forceBlockingFlush();
// second sstable is overlapping
Set<SSTableReader> overlapping = Sets.difference(Sets.newHashSet(cfs.getLiveSSTables()), compacting);
// the first sstable should be expired because the overlapping sstable is newer and the gc period is later
int gcBefore = (int) (System.currentTimeMillis() / 1000) + 5;
Set<SSTableReader> expired = CompactionController.getFullyExpiredSSTables(cfs, compacting, overlapping, gcBefore);
assertNotNull(expired);
assertEquals(1, expired.size());
assertEquals(compacting.iterator().next(), expired.iterator().next());
// however if we add an older mutation to the memtable then the sstable should not be expired
applyMutation(cfs.metadata, key, timestamp3);
expired = CompactionController.getFullyExpiredSSTables(cfs, compacting, overlapping, gcBefore);
assertNotNull(expired);
assertEquals(0, expired.size());
}
示例15: testTransferRangeTombstones
import org.apache.cassandra.utils.FBUtilities; //导入方法依赖的package包/类
/**
* Test to make sure RangeTombstones at column index boundary transferred correctly.
*/
@Test
public void testTransferRangeTombstones() throws Exception
{
String ks = KEYSPACE1;
String cfname = "StandardInteger1";
Keyspace keyspace = Keyspace.open(ks);
ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(cfname);
ClusteringComparator comparator = cfs.getComparator();
String key = "key1";
RowUpdateBuilder updates = new RowUpdateBuilder(cfs.metadata, FBUtilities.timestampMicros(), key);
// add columns of size slightly less than column_index_size to force insert column index
updates.clustering(1)
.add("val", ByteBuffer.wrap(new byte[DatabaseDescriptor.getColumnIndexSize() - 64]))
.build()
.apply();
updates = new RowUpdateBuilder(cfs.metadata, FBUtilities.timestampMicros(), key);
updates.clustering(6)
.add("val", ByteBuffer.wrap(new byte[DatabaseDescriptor.getColumnIndexSize()]))
.build()
.apply();
// add RangeTombstones
//updates = new RowUpdateBuilder(cfs.metadata, FBUtilities.timestampMicros() + 1 , key);
//updates.addRangeTombstone(Slice.make(comparator, comparator.make(2), comparator.make(4)))
// .build()
// .apply();
updates = new RowUpdateBuilder(cfs.metadata, FBUtilities.timestampMicros() + 1, key);
updates.addRangeTombstone(Slice.make(comparator.make(5), comparator.make(7)))
.build()
.apply();
cfs.forceBlockingFlush();
SSTableReader sstable = cfs.getLiveSSTables().iterator().next();
cfs.clearUnsafe();
transferSSTables(sstable);
// confirm that a single SSTable was transferred and registered
assertEquals(1, cfs.getLiveSSTables().size());
Row r = Util.getOnlyRow(Util.cmd(cfs).build());
Assert.assertFalse(r.isEmpty());
Assert.assertTrue(1 == Int32Type.instance.compose(r.clustering().get(0)));
}