Esempio n. 1
0
  @Test
  public void testPuttingBackChunksAfterFlushing() throws UnexpectedStateException {
    byte[] row = Bytes.toBytes("testrow");
    byte[] fam = Bytes.toBytes("testfamily");
    byte[] qf1 = Bytes.toBytes("testqualifier1");
    byte[] qf2 = Bytes.toBytes("testqualifier2");
    byte[] qf3 = Bytes.toBytes("testqualifier3");
    byte[] qf4 = Bytes.toBytes("testqualifier4");
    byte[] qf5 = Bytes.toBytes("testqualifier5");
    byte[] val = Bytes.toBytes("testval");

    DefaultMemStore memstore = new DefaultMemStore();

    // Setting up memstore
    memstore.add(new KeyValue(row, fam, qf1, val));
    memstore.add(new KeyValue(row, fam, qf2, val));
    memstore.add(new KeyValue(row, fam, qf3, val));

    // Creating a snapshot
    MemStoreSnapshot snapshot = memstore.snapshot();
    assertEquals(3, memstore.getSnapshot().getCellsCount());

    // Adding value to "new" memstore
    assertEquals(0, memstore.getActive().getCellsCount());
    memstore.add(new KeyValue(row, fam, qf4, val));
    memstore.add(new KeyValue(row, fam, qf5, val));
    assertEquals(2, memstore.getActive().getCellsCount());
    memstore.clearSnapshot(snapshot.getId());

    int chunkCount = chunkPool.getPoolSize();
    assertTrue(chunkCount > 0);
  }
Esempio n. 2
0
 /**
  * Code to help figure if our approximation of object heap sizes is close enough. See hbase-900.
  * Fills memstores then waits so user can heap dump and bring up resultant hprof in something like
  * jprofiler which allows you get 'deep size' on objects.
  *
  * @param args main args
  */
 public static void main(String[] args) {
   RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
   LOG.info(
       "vmName="
           + runtime.getVmName()
           + ", vmVendor="
           + runtime.getVmVendor()
           + ", vmVersion="
           + runtime.getVmVersion());
   LOG.info("vmInputArguments=" + runtime.getInputArguments());
   DefaultMemStore memstore1 = new DefaultMemStore();
   // TODO: x32 vs x64
   long size = 0;
   final int count = 10000;
   byte[] fam = Bytes.toBytes("col");
   byte[] qf = Bytes.toBytes("umn");
   byte[] empty = new byte[0];
   for (int i = 0; i < count; i++) {
     // Give each its own ts
     size += memstore1.add(new KeyValue(Bytes.toBytes(i), fam, qf, i, empty));
   }
   LOG.info("memstore1 estimated size=" + size);
   for (int i = 0; i < count; i++) {
     size += memstore1.add(new KeyValue(Bytes.toBytes(i), fam, qf, i, empty));
   }
   LOG.info("memstore1 estimated size (2nd loading of same data)=" + size);
   // Make a variably sized memstore.
   DefaultMemStore memstore2 = new DefaultMemStore();
   for (int i = 0; i < count; i++) {
     size += memstore2.add(new KeyValue(Bytes.toBytes(i), fam, qf, i, new byte[i]));
   }
   LOG.info("memstore2 estimated size=" + size);
   final int seconds = 30;
   LOG.info("Waiting " + seconds + " seconds while heap dump is taken");
   LOG.info("Exiting.");
 }
Esempio n. 3
0
  @Test
  public void testPuttingBackChunksWithOpeningScanner() throws IOException {
    byte[] row = Bytes.toBytes("testrow");
    byte[] fam = Bytes.toBytes("testfamily");
    byte[] qf1 = Bytes.toBytes("testqualifier1");
    byte[] qf2 = Bytes.toBytes("testqualifier2");
    byte[] qf3 = Bytes.toBytes("testqualifier3");
    byte[] qf4 = Bytes.toBytes("testqualifier4");
    byte[] qf5 = Bytes.toBytes("testqualifier5");
    byte[] qf6 = Bytes.toBytes("testqualifier6");
    byte[] qf7 = Bytes.toBytes("testqualifier7");
    byte[] val = Bytes.toBytes("testval");

    DefaultMemStore memstore = new DefaultMemStore();

    // Setting up memstore
    memstore.add(new KeyValue(row, fam, qf1, val));
    memstore.add(new KeyValue(row, fam, qf2, val));
    memstore.add(new KeyValue(row, fam, qf3, val));

    // Creating a snapshot
    MemStoreSnapshot snapshot = memstore.snapshot();
    assertEquals(3, memstore.getSnapshot().getCellsCount());

    // Adding value to "new" memstore
    assertEquals(0, memstore.getActive().getCellsCount());
    memstore.add(new KeyValue(row, fam, qf4, val));
    memstore.add(new KeyValue(row, fam, qf5, val));
    assertEquals(2, memstore.getActive().getCellsCount());

    // opening scanner before clear the snapshot
    List<KeyValueScanner> scanners = memstore.getScanners(0);
    // Shouldn't putting back the chunks to pool,since some scanners are opening
    // based on their data
    memstore.clearSnapshot(snapshot.getId());

    assertTrue(chunkPool.getPoolSize() == 0);

    // Chunks will be put back to pool after close scanners;
    for (KeyValueScanner scanner : scanners) {
      scanner.close();
    }
    assertTrue(chunkPool.getPoolSize() > 0);

    // clear chunks
    chunkPool.clearChunks();

    // Creating another snapshot
    snapshot = memstore.snapshot();
    // Adding more value
    memstore.add(new KeyValue(row, fam, qf6, val));
    memstore.add(new KeyValue(row, fam, qf7, val));
    // opening scanners
    scanners = memstore.getScanners(0);
    // close scanners before clear the snapshot
    for (KeyValueScanner scanner : scanners) {
      scanner.close();
    }
    // Since no opening scanner, the chunks of snapshot should be put back to
    // pool
    memstore.clearSnapshot(snapshot.getId());
    assertTrue(chunkPool.getPoolSize() > 0);
  }