@BeforeClass
 public static void defineSchema() throws ConfigurationException {
   SchemaLoader.prepareServer();
   SchemaLoader.createKeyspace(
       KEYSPACE4,
       SimpleStrategy.class,
       KSMetaData.optsWithRF(1),
       SchemaLoader.standardCFMD(KEYSPACE4, STANDARD1_CF));
 }
  public static void initialize() throws IOException, ConfigurationException {
    try (FileInputStream fis = new FileInputStream("CHANGES.txt")) {
      dataSource = ByteBuffer.allocateDirect((int) fis.getChannel().size());
      while (dataSource.hasRemaining()) {
        fis.getChannel().read(dataSource);
      }
      dataSource.flip();
    }

    SchemaLoader.loadSchema();
    SchemaLoader.schemaDefinition("");
  }
  @Test
  public void testClientOnlyMode() throws IOException, ConfigurationException {
    SchemaLoader.mkdirs();
    SchemaLoader.cleanup();
    StorageService.instance.initClient(0);

    // verify that no storage directories were created.
    for (String path : DatabaseDescriptor.getAllDataFileLocations()) {
      assertFalse(new File(path).exists());
    }
    StorageService.instance.stopClient();
  }
 @BeforeClass
 public static void defineSchema() throws ConfigurationException {
   SchemaLoader.prepareServer();
   SchemaLoader.createKeyspace(
       KEYSPACE_CACHED,
       SimpleStrategy.class,
       KSMetaData.optsWithRF(1),
       SchemaLoader.standardCFMD(KEYSPACE_CACHED, CF_CACHED).caching(CachingOptions.ALL),
       SchemaLoader.standardCFMD(KEYSPACE_CACHED, CF_CACHEDINT)
           .defaultValidator(IntegerType.instance)
           .caching(
               new CachingOptions(
                   new CachingOptions.KeyCache(CachingOptions.KeyCache.Type.ALL),
                   new CachingOptions.RowCache(CachingOptions.RowCache.Type.HEAD, 100))));
 }
 @BeforeClass
 public static void setUpClass() throws Throwable {
   SchemaLoader.loadSchema();
   executeSchemaChange(
       "CREATE KEYSPACE IF NOT EXISTS %s WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'}");
   clientState = ClientState.forInternalCalls();
 }
Esempio n. 6
0
  @Test
  public void testCompactionLog() throws Exception {
    SystemKeyspace.discardCompactionsInProgress();

    String cf = "Standard4";
    ColumnFamilyStore cfs = Keyspace.open(KEYSPACE1).getColumnFamilyStore(cf);
    SchemaLoader.insertData(KEYSPACE1, cf, 0, 1);
    cfs.forceBlockingFlush();

    Collection<SSTableReader> sstables = cfs.getSSTables();
    assertFalse(sstables.isEmpty());
    Set<Integer> generations =
        Sets.newHashSet(
            Iterables.transform(
                sstables,
                new Function<SSTableReader, Integer>() {
                  public Integer apply(SSTableReader sstable) {
                    return sstable.descriptor.generation;
                  }
                }));
    UUID taskId = SystemKeyspace.startCompaction(cfs, sstables);
    Map<Pair<String, String>, Map<Integer, UUID>> compactionLogs =
        SystemKeyspace.getUnfinishedCompactions();
    Set<Integer> unfinishedCompactions = compactionLogs.get(Pair.create(KEYSPACE1, cf)).keySet();
    assertTrue(unfinishedCompactions.containsAll(generations));

    SystemKeyspace.finishCompaction(taskId);
    compactionLogs = SystemKeyspace.getUnfinishedCompactions();
    assertFalse(compactionLogs.containsKey(Pair.create(KEYSPACE1, cf)));
  }
Esempio n. 7
0
 @BeforeClass
 public static void defineSchema() throws ConfigurationException {
   Map<String, String> compactionOptions = new HashMap<>();
   compactionOptions.put("tombstone_compaction_interval", "1");
   SchemaLoader.prepareServer();
   SchemaLoader.createKeyspace(
       KEYSPACE1,
       SimpleStrategy.class,
       KSMetaData.optsWithRF(1),
       SchemaLoader.standardCFMD(KEYSPACE1, CF_STANDARD1)
           .compactionStrategyOptions(compactionOptions),
       SchemaLoader.standardCFMD(KEYSPACE1, CF_STANDARD2),
       SchemaLoader.standardCFMD(KEYSPACE1, CF_STANDARD3),
       SchemaLoader.standardCFMD(KEYSPACE1, CF_STANDARD4),
       SchemaLoader.superCFMD(KEYSPACE1, CF_SUPER1, LongType.instance),
       SchemaLoader.superCFMD(KEYSPACE1, CF_SUPER5, BytesType.instance),
       SchemaLoader.superCFMD(KEYSPACE1, CF_SUPERGC, BytesType.instance).gcGraceSeconds(0));
 }
  public void rowCacheLoad(int totalKeys, int keysToSave, int offset) throws Exception {
    CompactionManager.instance.disableAutoCompaction();

    ColumnFamilyStore store = Keyspace.open(KEYSPACE_CACHED).getColumnFamilyStore(CF_CACHED);

    // empty the cache
    CacheService.instance.invalidateRowCache();
    assertEquals(0, CacheService.instance.rowCache.size());

    // insert data and fill the cache
    SchemaLoader.insertData(KEYSPACE_CACHED, CF_CACHED, offset, totalKeys);
    SchemaLoader.readData(KEYSPACE_CACHED, CF_CACHED, offset, totalKeys);
    assertEquals(totalKeys, CacheService.instance.rowCache.size());

    // force the cache to disk
    CacheService.instance.rowCache.submitWrite(keysToSave).get();

    // empty the cache again to make sure values came from disk
    CacheService.instance.invalidateRowCache();
    assertEquals(0, CacheService.instance.rowCache.size());
    assertEquals(
        keysToSave == Integer.MAX_VALUE ? totalKeys : keysToSave,
        CacheService.instance.rowCache.loadSaved());
  }
 @BeforeClass
 public static void defineSchema() throws Exception {
   partitionerSwitcher = Util.switchPartitioner(partitioner);
   SchemaLoader.loadSchema();
   SchemaLoader.schemaDefinition("LeaveAndBootstrapTest");
 }
  @Test
  public void testRowCache() throws Exception {
    CompactionManager.instance.disableAutoCompaction();

    Keyspace keyspace = Keyspace.open(KEYSPACE_CACHED);
    ColumnFamilyStore cachedStore = keyspace.getColumnFamilyStore(CF_CACHED);

    // empty the row cache
    CacheService.instance.invalidateRowCache();

    // set global row cache size to 1 MB
    CacheService.instance.setRowCacheCapacityInMB(1);

    // inserting 100 rows into both column families
    SchemaLoader.insertData(KEYSPACE_CACHED, CF_CACHED, 0, 100);

    // now reading rows one by one and checking if row change grows
    for (int i = 0; i < 100; i++) {
      DecoratedKey key = Util.dk("key" + i);

      cachedStore.getColumnFamily(
          key, Composites.EMPTY, Composites.EMPTY, false, 1, System.currentTimeMillis());
      assert CacheService.instance.rowCache.size() == i + 1;
      assert cachedStore.containsCachedRow(key); // current key should be stored in the cache

      // checking if cell is read correctly after cache
      ColumnFamily cf =
          cachedStore.getColumnFamily(
              key, Composites.EMPTY, Composites.EMPTY, false, 1, System.currentTimeMillis());
      Collection<Cell> cells = cf.getSortedColumns();

      Cell cell = cells.iterator().next();

      assert cells.size() == 1;
      assert cell.name().toByteBuffer().equals(ByteBufferUtil.bytes("col" + i));
      assert cell.value().equals(ByteBufferUtil.bytes("val" + i));
    }

    // insert 10 more keys
    SchemaLoader.insertData(KEYSPACE_CACHED, CF_CACHED, 100, 10);

    for (int i = 100; i < 110; i++) {
      DecoratedKey key = Util.dk("key" + i);

      cachedStore.getColumnFamily(
          key, Composites.EMPTY, Composites.EMPTY, false, 1, System.currentTimeMillis());
      assert cachedStore.containsCachedRow(
          key); // cache should be populated with the latest rows read (old ones should be popped)

      // checking if cell is read correctly after cache
      ColumnFamily cf =
          cachedStore.getColumnFamily(
              key, Composites.EMPTY, Composites.EMPTY, false, 1, System.currentTimeMillis());
      Collection<Cell> cells = cf.getSortedColumns();

      Cell cell = cells.iterator().next();

      assert cells.size() == 1;
      assert cell.name().toByteBuffer().equals(ByteBufferUtil.bytes("col" + i));
      assert cell.value().equals(ByteBufferUtil.bytes("val" + i));
    }

    // clear 100 rows from the cache
    int keysLeft = 109;
    for (int i = 109; i >= 10; i--) {
      cachedStore.invalidateCachedRow(Util.dk("key" + i));
      assert CacheService.instance.rowCache.size() == keysLeft;
      keysLeft--;
    }

    CacheService.instance.setRowCacheCapacityInMB(0);
  }
 @AfterClass
 public static void cleanup() {
   SchemaLoader.cleanupSavedCaches();
 }
Esempio n. 12
0
 @AfterClass
 public static void tearDownClass() {
   StorageService.instance.setPartitionerUnsafe(oldPartitioner);
   SchemaLoader.stopGossiper();
 }
Esempio n. 13
0
 @BeforeClass
 public static void setupClass() throws IOException {
   oldPartitioner = StorageService.instance.setPartitionerUnsafe(partitioner);
   SchemaLoader.loadSchema();
 }