本文整理汇总了Java中org.apache.cassandra.dht.BytesToken类的典型用法代码示例。如果您正苦于以下问题:Java BytesToken类的具体用法?Java BytesToken怎么用?Java BytesToken使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BytesToken类属于org.apache.cassandra.dht包,在下文中一共展示了BytesToken类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: antiCompactionSizeTest
import org.apache.cassandra.dht.BytesToken; //导入依赖的package包/类
@Test
public void antiCompactionSizeTest() throws ExecutionException, InterruptedException, IOException
{
Keyspace keyspace = Keyspace.open(KEYSPACE1);
ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(CF);
cfs.disableAutoCompaction();
SSTableReader s = writeFile(cfs, 1000);
cfs.addSSTable(s);
long origSize = s.bytesOnDisk();
Range<Token> range = new Range<Token>(new BytesToken(ByteBufferUtil.bytes(0)), new BytesToken(ByteBufferUtil.bytes(500)));
Collection<SSTableReader> sstables = cfs.getSSTables();
CompactionManager.instance.performAnticompaction(cfs, Arrays.asList(range), Refs.tryRef(sstables), 12345);
long sum = 0;
for (SSTableReader x : cfs.getSSTables())
sum += x.bytesOnDisk();
assertEquals(sum, cfs.metric.liveDiskSpaceUsed.count());
assertEquals(origSize, cfs.metric.liveDiskSpaceUsed.count(), 100000);
}
示例2: shouldSkipAntiCompactionForNonIntersectingRange
import org.apache.cassandra.dht.BytesToken; //导入依赖的package包/类
@Test
public void shouldSkipAntiCompactionForNonIntersectingRange() throws InterruptedException, ExecutionException, IOException
{
ColumnFamilyStore store = prepareColumnFamilyStore();
Collection<SSTableReader> sstables = store.getUnrepairedSSTables();
assertEquals(store.getSSTables().size(), sstables.size());
Range<Token> range = new Range<Token>(new BytesToken("-10".getBytes()), new BytesToken("-1".getBytes()));
List<Range<Token>> ranges = Arrays.asList(range);
Refs<SSTableReader> refs = Refs.tryRef(sstables);
if (refs == null)
throw new IllegalStateException();
CompactionManager.instance.performAnticompaction(store, ranges, refs, 1);
assertThat(store.getSSTables().size(), is(1));
assertThat(Iterables.get(store.getSSTables(), 0).isRepaired(), is(false));
assertThat(Iterables.get(store.getSSTables(), 0).selfRef().globalCount(), is(1));
assertThat(store.getDataTracker().getCompacting().size(), is(0));
}
示例3: shouldMutateRepairedAt
import org.apache.cassandra.dht.BytesToken; //导入依赖的package包/类
@Test
public void shouldMutateRepairedAt() throws InterruptedException, ExecutionException, IOException
{
ColumnFamilyStore store = prepareColumnFamilyStore();
Collection<SSTableReader> sstables = store.getUnrepairedSSTables();
assertEquals(store.getSSTables().size(), sstables.size());
Range<Token> range = new Range<Token>(new BytesToken("0".getBytes()), new BytesToken("9999".getBytes()));
List<Range<Token>> ranges = Arrays.asList(range);
CompactionManager.instance.performAnticompaction(store, ranges, Refs.tryRef(sstables), 1);
assertThat(store.getSSTables().size(), is(1));
assertThat(Iterables.get(store.getSSTables(), 0).isRepaired(), is(true));
assertThat(Iterables.get(store.getSSTables(), 0).selfRef().globalCount(), is(1));
assertThat(store.getDataTracker().getCompacting().size(), is(0));
}
示例4: testRowCacheCleanup
import org.apache.cassandra.dht.BytesToken; //导入依赖的package包/类
@Test
public void testRowCacheCleanup() throws Exception
{
StorageService.instance.initServer(0);
CacheService.instance.setRowCacheCapacityInMB(1);
rowCacheLoad(100, Integer.MAX_VALUE, 1000);
ColumnFamilyStore store = Keyspace.open(KEYSPACE).getColumnFamilyStore(COLUMN_FAMILY);
assertEquals(CacheService.instance.rowCache.getKeySet().size(), 100);
store.cleanupCache();
assertEquals(CacheService.instance.rowCache.getKeySet().size(), 100);
TokenMetadata tmd = StorageService.instance.getTokenMetadata();
byte[] tk1, tk2;
tk1 = "key1000".getBytes();
tk2 = "key1050".getBytes();
tmd.updateNormalToken(new BytesToken(tk1), InetAddress.getByName("127.0.0.1"));
tmd.updateNormalToken(new BytesToken(tk2), InetAddress.getByName("127.0.0.2"));
store.cleanupCache();
assertEquals(CacheService.instance.rowCache.getKeySet().size(), 50);
CacheService.instance.setRowCacheCapacityInMB(0);
}
示例5: shouldSkipAntiCompactionForNonIntersectingRange
import org.apache.cassandra.dht.BytesToken; //导入依赖的package包/类
@Test
public void shouldSkipAntiCompactionForNonIntersectingRange() throws InterruptedException, ExecutionException, IOException
{
Keyspace keyspace = Keyspace.open(KEYSPACE1);
ColumnFamilyStore store = keyspace.getColumnFamilyStore(CF);
store.disableAutoCompaction();
for (int table = 0; table < 10; table++)
{
generateSStable(store,Integer.toString(table));
}
Collection<SSTableReader> sstables = store.getUnrepairedSSTables();
assertEquals(store.getSSTables().size(), sstables.size());
Range<Token> range = new Range<Token>(new BytesToken("-10".getBytes()), new BytesToken("-1".getBytes()));
List<Range<Token>> ranges = Arrays.asList(range);
SSTableReader.acquireReferences(sstables);
CompactionManager.instance.performAnticompaction(store, ranges, sstables, 0);
assertThat(store.getSSTables().size(), is(10));
assertThat(Iterables.get(store.getSSTables(), 0).isRepaired(), is(false));
}
示例6: testRowCacheCleanup
import org.apache.cassandra.dht.BytesToken; //导入依赖的package包/类
@Test
public void testRowCacheCleanup() throws Exception
{
StorageService.instance.initServer(0);
CacheService.instance.setRowCacheCapacityInMB(1);
rowCacheLoad(100, Integer.MAX_VALUE, 1000);
ColumnFamilyStore store = Keyspace.open(KEYSPACE_CACHED).getColumnFamilyStore(CF_CACHED);
assertEquals(CacheService.instance.rowCache.getKeySet().size(), 100);
store.cleanupCache();
assertEquals(CacheService.instance.rowCache.getKeySet().size(), 100);
TokenMetadata tmd = StorageService.instance.getTokenMetadata();
byte[] tk1, tk2;
tk1 = "key1000".getBytes();
tk2 = "key1050".getBytes();
tmd.updateNormalToken(new BytesToken(tk1), InetAddress.getByName("127.0.0.1"));
tmd.updateNormalToken(new BytesToken(tk2), InetAddress.getByName("127.0.0.2"));
store.cleanupCache();
assertEquals(CacheService.instance.rowCache.getKeySet().size(), 50);
CacheService.instance.setRowCacheCapacityInMB(0);
}
示例7: testStreamRequestMessageWrite
import org.apache.cassandra.dht.BytesToken; //导入依赖的package包/类
private void testStreamRequestMessageWrite() throws IOException
{
UUID sessionId = UUIDGen.getTimeUUID();
Collection<Range<Token>> ranges = new ArrayList<Range<Token>>();
for (int i = 0; i < 5; i++)
ranges.add(new Range<Token>(new BytesToken(ByteBufferUtil.bytes(Integer.toString(10*i))), new BytesToken(ByteBufferUtil.bytes(Integer.toString(10*i+5)))));
List<ColumnFamilyStore> stores = Collections.singletonList(Table.open("Keyspace1").getColumnFamilyStore("Standard1"));
StreamRequest msg0 = new StreamRequest(FBUtilities.getBroadcastAddress(), ranges, "Keyspace1", stores, sessionId, OperationType.RESTORE_REPLICA_COUNT);
StreamRequest msg1 = new StreamRequest(FBUtilities.getBroadcastAddress(), makePendingFile(true, 100, OperationType.BOOTSTRAP), sessionId);
StreamRequest msg2 = new StreamRequest(FBUtilities.getBroadcastAddress(), makePendingFile(false, 100, OperationType.BOOTSTRAP), sessionId);
DataOutputStream out = getOutput("streaming.StreamRequestMessage.bin");
StreamRequest.serializer.serialize(msg0, out, getVersion());
StreamRequest.serializer.serialize(msg1, out, getVersion());
StreamRequest.serializer.serialize(msg2, out, getVersion());
msg0.createMessage().serialize(out, getVersion());
msg1.createMessage().serialize(out, getVersion());
msg2.createMessage().serialize(out, getVersion());
out.close();
// test serializedSize
testSerializedSize(msg0, StreamRequest.serializer);
testSerializedSize(msg1, StreamRequest.serializer);
testSerializedSize(msg2, StreamRequest.serializer);
}
示例8: testStreamRequestMessageWrite
import org.apache.cassandra.dht.BytesToken; //导入依赖的package包/类
private void testStreamRequestMessageWrite() throws IOException
{
Collection<Range> ranges = new ArrayList<Range>();
for (int i = 0; i < 5; i++)
ranges.add(new Range(new BytesToken(ByteBufferUtil.bytes(Integer.toString(10*i))), new BytesToken(ByteBufferUtil.bytes(Integer.toString(10*i+5)))));
StreamRequestMessage msg0 = new StreamRequestMessage(FBUtilities.getLocalAddress(), ranges, "Keyspace1", 123L, OperationType.RESTORE_REPLICA_COUNT);
StreamRequestMessage msg1 = new StreamRequestMessage(FBUtilities.getLocalAddress(), makePendingFile(true, 100, OperationType.BOOTSTRAP), 124L);
StreamRequestMessage msg2 = new StreamRequestMessage(FBUtilities.getLocalAddress(), makePendingFile(false, 100, OperationType.BOOTSTRAP), 124L);
DataOutputStream out = getOutput("streaming.StreamRequestMessage.bin");
StreamRequestMessage.serializer().serialize(msg0, out, getVersion());
StreamRequestMessage.serializer().serialize(msg1, out, getVersion());
StreamRequestMessage.serializer().serialize(msg2, out, getVersion());
Message.serializer().serialize(msg0.getMessage(getVersion()), out, getVersion());
Message.serializer().serialize(msg1.getMessage(getVersion()), out, getVersion());
Message.serializer().serialize(msg2.getMessage(getVersion()), out, getVersion());
out.close();
}
示例9: testCleanupWithNewToken
import org.apache.cassandra.dht.BytesToken; //导入依赖的package包/类
@Test
public void testCleanupWithNewToken() throws ExecutionException, InterruptedException, UnknownHostException
{
StorageService.instance.getTokenMetadata().clearUnsafe();
Keyspace keyspace = Keyspace.open(KEYSPACE1);
ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(CF2);
List<Row> rows;
// insert data and verify we get it back w/ range query
fillCF(cfs, LOOPS);
rows = Util.getRangeSlice(cfs);
assertEquals(LOOPS, rows.size());
TokenMetadata tmd = StorageService.instance.getTokenMetadata();
byte[] tk1 = new byte[1], tk2 = new byte[1];
tk1[0] = 2;
tk2[0] = 1;
tmd.updateNormalToken(new BytesToken(tk1), InetAddress.getByName("127.0.0.1"));
tmd.updateNormalToken(new BytesToken(tk2), InetAddress.getByName("127.0.0.2"));
CompactionManager.instance.performCleanup(cfs);
rows = Util.getRangeSlice(cfs);
assertEquals(0, rows.size());
}
示例10: rangeFor
import org.apache.cassandra.dht.BytesToken; //导入依赖的package包/类
private static Range<Token> rangeFor(int start, int end)
{
return new Range<Token>(new BytesToken(String.format("%03d", start).getBytes()),
new BytesToken(String.format("%03d", end).getBytes()));
}
示例11: boundsFor
import org.apache.cassandra.dht.BytesToken; //导入依赖的package包/类
private static Bounds<RowPosition> boundsFor(int start, int end)
{
return new Bounds<RowPosition>(new BytesToken(toKey(start).getBytes()).minKeyBound(),
new BytesToken(toKey(end).getBytes()).maxKeyBound());
}
示例12: rangeFor
import org.apache.cassandra.dht.BytesToken; //导入依赖的package包/类
private static Range<Token> rangeFor(int start, int end)
{
return new Range<Token>(new BytesToken(toKey(start).getBytes()),
new BytesToken(toKey(end).getBytes()));
}
示例13: antiCompactOne
import org.apache.cassandra.dht.BytesToken; //导入依赖的package包/类
@Test
public void antiCompactOne() throws InterruptedException, ExecutionException, IOException
{
Keyspace keyspace = Keyspace.open(KEYSPACE1);
ColumnFamilyStore store = keyspace.getColumnFamilyStore(CF);
store.disableAutoCompaction();
long timestamp = System.currentTimeMillis();
for (int i = 0; i < 10; i++)
{
DecoratedKey key = Util.dk(Integer.toString(i));
Mutation rm = new Mutation(KEYSPACE1, key.getKey());
for (int j = 0; j < 10; j++)
rm.add(CF, Util.cellname(Integer.toString(j)),
ByteBufferUtil.EMPTY_BYTE_BUFFER,
timestamp,
0);
rm.applyUnsafe();
}
store.forceBlockingFlush();
Collection<SSTableReader> sstables = store.getUnrepairedSSTables();
assertEquals(store.getSSTables().size(), sstables.size());
Range<Token> range = new Range<Token>(new BytesToken("0".getBytes()), new BytesToken("4".getBytes()));
List<Range<Token>> ranges = Arrays.asList(range);
SSTableReader.acquireReferences(sstables);
long repairedAt = 1000;
CompactionManager.instance.performAnticompaction(store, ranges, sstables, repairedAt);
assertEquals(2, store.getSSTables().size());
int repairedKeys = 0;
int nonRepairedKeys = 0;
for (SSTableReader sstable : store.getSSTables())
{
SSTableScanner scanner = sstable.getScanner();
while (scanner.hasNext())
{
SSTableIdentityIterator row = (SSTableIdentityIterator) scanner.next();
if (sstable.isRepaired())
{
assertTrue(range.contains(row.getKey().getToken()));
repairedKeys++;
}
else
{
assertFalse(range.contains(row.getKey().getToken()));
nonRepairedKeys++;
}
}
}
assertEquals(repairedKeys, 4);
assertEquals(nonRepairedKeys, 6);
}
示例14: antiCompactTen
import org.apache.cassandra.dht.BytesToken; //导入依赖的package包/类
public void antiCompactTen(String compactionStrategy) throws InterruptedException, ExecutionException, IOException
{
Keyspace keyspace = Keyspace.open(KEYSPACE1);
ColumnFamilyStore store = keyspace.getColumnFamilyStore(CF);
store.setCompactionStrategyClass(compactionStrategy);
store.disableAutoCompaction();
for (int table = 0; table < 10; table++)
{
generateSStable(store,Integer.toString(table));
}
Collection<SSTableReader> sstables = store.getUnrepairedSSTables();
assertEquals(store.getSSTables().size(), sstables.size());
Range<Token> range = new Range<Token>(new BytesToken("0".getBytes()), new BytesToken("4".getBytes()));
List<Range<Token>> ranges = Arrays.asList(range);
SSTableReader.acquireReferences(sstables);
long repairedAt = 1000;
CompactionManager.instance.performAnticompaction(store, ranges, sstables, repairedAt);
/*
Anticompaction will be anti-compacting 10 SSTables but will be doing this two at a time
so there will be no net change in the number of sstables
*/
assertEquals(10, store.getSSTables().size());
int repairedKeys = 0;
int nonRepairedKeys = 0;
for (SSTableReader sstable : store.getSSTables())
{
SSTableScanner scanner = sstable.getScanner();
while (scanner.hasNext())
{
SSTableIdentityIterator row = (SSTableIdentityIterator) scanner.next();
if (sstable.isRepaired())
{
assertTrue(range.contains(row.getKey().getToken()));
assertEquals(repairedAt, sstable.getSSTableMetadata().repairedAt);
repairedKeys++;
}
else
{
assertFalse(range.contains(row.getKey().getToken()));
assertEquals(ActiveRepairService.UNREPAIRED_SSTABLE, sstable.getSSTableMetadata().repairedAt);
nonRepairedKeys++;
}
}
}
assertEquals(repairedKeys, 40);
assertEquals(nonRepairedKeys, 60);
}
示例15: antiCompactOne
import org.apache.cassandra.dht.BytesToken; //导入依赖的package包/类
@Test
public void antiCompactOne() throws InterruptedException, ExecutionException, IOException
{
Keyspace keyspace = Keyspace.open(KEYSPACE1);
ColumnFamilyStore store = keyspace.getColumnFamilyStore(CF);
store.disableAutoCompaction();
long timestamp = System.currentTimeMillis();
for (int i = 0; i < 10; i++)
{
DecoratedKey key = Util.dk(Integer.toString(i));
Mutation rm = new Mutation(KEYSPACE1, key.key);
for (int j = 0; j < 10; j++)
rm.add("Standard1", Util.cellname(Integer.toString(j)),
ByteBufferUtil.EMPTY_BYTE_BUFFER,
timestamp,
0);
rm.apply();
}
store.forceBlockingFlush();
Collection<SSTableReader> sstables = store.getUnrepairedSSTables();
assertEquals(store.getSSTables().size(), sstables.size());
Range<Token> range = new Range<Token>(new BytesToken("0".getBytes()), new BytesToken("4".getBytes()));
List<Range<Token>> ranges = Arrays.asList(range);
SSTableReader.acquireReferences(sstables);
long repairedAt = 1000;
CompactionManager.instance.performAnticompaction(store, ranges, sstables, repairedAt);
assertEquals(2, store.getSSTables().size());
int repairedKeys = 0;
int nonRepairedKeys = 0;
for (SSTableReader sstable : store.getSSTables())
{
SSTableScanner scanner = sstable.getScanner();
while (scanner.hasNext())
{
SSTableIdentityIterator row = (SSTableIdentityIterator) scanner.next();
if (sstable.isRepaired())
{
assertTrue(range.contains(row.getKey().token));
repairedKeys++;
}
else
{
assertFalse(range.contains(row.getKey().token));
nonRepairedKeys++;
}
}
}
assertEquals(repairedKeys, 4);
assertEquals(nonRepairedKeys, 6);
}