コード例 #1
0
  protected void testCompaction(int sstableCount, int rowsPerSSTable, int colsPerRow)
      throws Exception {
    CompactionManager.instance.disableAutoCompaction();

    Table table = Table.open(TABLE1);
    ColumnFamilyStore store = table.getColumnFamilyStore("Standard1");

    ArrayList<SSTableReader> sstables = new ArrayList<SSTableReader>();
    for (int k = 0; k < sstableCount; k++) {
      SortedMap<String, ColumnFamily> rows = new TreeMap<String, ColumnFamily>();
      for (int j = 0; j < rowsPerSSTable; j++) {
        String key = String.valueOf(j);
        IColumn[] cols = new IColumn[colsPerRow];
        for (int i = 0; i < colsPerRow; i++) {
          // last sstable has highest timestamps
          cols[i] = Util.column(String.valueOf(i), String.valueOf(i), k);
        }
        rows.put(key, SSTableUtils.createCF(Long.MIN_VALUE, Integer.MIN_VALUE, cols));
      }
      SSTableReader sstable = SSTableUtils.writeSSTable(rows);
      sstables.add(sstable);
      store.addSSTable(sstable);
    }

    // give garbage collection a bit of time to catch up
    Thread.sleep(1000);

    long start = System.currentTimeMillis();
    CompactionManager.instance.doCompaction(
        store,
        sstables,
        (int) (System.currentTimeMillis() / 1000)
            - DatabaseDescriptor.getCFMetaData(TABLE1, "Standard1").gcGraceSeconds);
    System.out.println(
        String.format(
            "%s: sstables=%d rowsper=%d colsper=%d: %d ms",
            this.getClass().getName(),
            sstableCount,
            rowsPerSSTable,
            colsPerRow,
            System.currentTimeMillis() - start));
  }
コード例 #2
0
 /**
  * Generates two sstables to be used to test migrating from a .json manifest to keeping the level
  * in the sstable metadata.
  *
  * <p>Do this: 1. remove @Ignore 2. comment out the @Before and @After methods above 3. run this
  * method 4. checkout trunk 5. copy the .json file from the previous version to the current one
  * (ie; test/data/migration-sstables/ic/Keyspace1/legacyleveled/legacyleveled.json) 6. update
  * LegacyLeveledManifestTest to use the new version.
  */
 @Test
 public void generateSSTable() throws IOException {
   File legacySSTableDir = getLegacySSTableDir(Descriptor.Version.current_version);
   FileUtils.createDirectory(legacySSTableDir);
   Set<String> keys = new HashSet<String>();
   for (int i = 0; i < 10; i++) {
     keys.add("key" + i);
   }
   for (int i = 0; i < 3; i++) {
     SSTableReader ssTable =
         SSTableUtils.prepare()
             .ks(KS)
             .cf(CF)
             .dest(new Descriptor(legacySSTableDir, KS, CF, i, false))
             .write(keys);
     System.out.println(ssTable);
   }
 }