Package com.yahoo.omid.client

Examples of com.yahoo.omid.client.TransactionalTable


   }

   @Test
   public void runTestMultiTableConflict() throws Exception {
      TransactionManager tm = new TransactionManager(conf);
      TransactionalTable tt = new TransactionalTable(conf, TEST_TABLE);
      String table2 = TEST_TABLE + 2;

      HBaseAdmin admin = new HBaseAdmin(conf);

      if (!admin.tableExists(table2)) {
         HTableDescriptor desc = new HTableDescriptor(table2);
         HColumnDescriptor datafam = new HColumnDescriptor(TEST_FAMILY);
         datafam.setMaxVersions(Integer.MAX_VALUE);
         desc.addFamily(datafam);

         admin.createTable(desc);
      }

      if (admin.isTableDisabled(table2)) {
         admin.enableTable(table2);
      }

      TransactionalTable tt2 = new TransactionalTable(conf, table2);

      TransactionState t1 = tm.beginTransaction();
      LOG.info("Transaction created " + t1);

      TransactionState t2 = tm.beginTransaction();
      LOG.info("Transaction created" + t2);

      byte[] row = Bytes.toBytes("test-simple");
      byte[] row2 = Bytes.toBytes("test-simple2");
      byte[] fam = Bytes.toBytes(TEST_FAMILY);
      byte[] col = Bytes.toBytes("testdata");
      byte[] data1 = Bytes.toBytes("testWrite-1");
      byte[] data2 = Bytes.toBytes("testWrite-2");

      Put p = new Put(row);
      p.add(fam, col, data1);
      tt.put(t1, p);
      tt2.put(t1, p);

      Put p2 = new Put(row);
      p2.add(fam, col, data2);
      tt.put(t2, p2);
      p2 = new Put(row2);
      p2.add(fam, col, data2);
      tt2.put(t2, p2);

      tm.tryCommit(t2);

      boolean aborted = false;
      try {
         tm.tryCommit(t1);
         assertTrue("Transaction commited successfully", false);
      } catch (CommitUnsuccessfulException e) {
         aborted = true;
      }
      assertTrue("Transaction didn't raise exception", aborted);

      ResultScanner rs = tt2.getScanner(Bytes.toBytes(TEST_FAMILY));
      int count = 0;
      Result r;
      while ((r = rs.next()) != null) {
         count += r.size();
      }
View Full Code Here


   }

   @Test
   public void runTestCleanupAfterConflict() throws Exception {
      TransactionManager tm = new TransactionManager(conf);
      TransactionalTable tt = new TransactionalTable(conf, TEST_TABLE);

      TransactionState t1 = tm.beginTransaction();
      LOG.info("Transaction created " + t1);

      TransactionState t2 = tm.beginTransaction();
      LOG.info("Transaction created" + t2);

      byte[] row = Bytes.toBytes("test-simple");
      byte[] fam = Bytes.toBytes(TEST_FAMILY);
      byte[] col = Bytes.toBytes("testdata");
      byte[] data1 = Bytes.toBytes("testWrite-1");
      byte[] data2 = Bytes.toBytes("testWrite-2");

      Put p = new Put(row);
      p.add(fam, col, data1);
      tt.put(t1, p);

      Get g = new Get(row).setMaxVersions();
      Result r = tt.get(g);
      assertEquals("Unexpected size for read.", 1, r.size());
      assertTrue("Unexpected value for read: " + Bytes.toString(r.getValue(fam, col)),
            Bytes.equals(data1, r.getValue(fam, col)));

      Put p2 = new Put(row);
      p2.add(fam, col, data2);
      tt.put(t2, p2);

      r = tt.get(g);
      assertEquals("Unexpected size for read.", 2, r.size());
      r = tt.get(t2, g);
      assertEquals("Unexpected size for read.", 1, r.size());
      assertTrue("Unexpected value for read: " + Bytes.toString(r.getValue(fam, col)),
            Bytes.equals(data2, r.getValue(fam, col)));

      tm.tryCommit(t1);

      boolean aborted = false;
      try {
         tm.tryCommit(t2);
         assertTrue("Transaction commited successfully", false);
      } catch (CommitUnsuccessfulException e) {
         aborted = true;
      }
      assertTrue("Transaction didn't raise exception", aborted);

      r = tt.get(g);
      assertEquals("Unexpected size for read.", 1, r.size());
      assertTrue("Unexpected value for read: " + Bytes.toString(r.getValue(fam, col)),
            Bytes.equals(data1, r.getValue(fam, col)));
   }
View Full Code Here

   @Test
   public void testCleanupWithDeleteRow() throws Exception {
      try {
         TransactionManager tm = new TransactionManager(conf);
         TransactionalTable tt = new TransactionalTable(conf, TEST_TABLE);

         TransactionState t1 = tm.beginTransaction();
         LOG.info("Transaction created " + t1);

         int rowcount = 10;
         int count = 0;

         byte[] fam = Bytes.toBytes(TEST_FAMILY);
         byte[] col = Bytes.toBytes("testdata");
         byte[] data1 = Bytes.toBytes("testWrite-1");
         byte[] data2 = Bytes.toBytes("testWrite-2");

         byte[] modrow = Bytes.toBytes("test-del" + 3);
         for (int i = 0; i < rowcount; i++) {
            byte[] row = Bytes.toBytes("test-del" + i);

            Put p = new Put(row);
            p.add(fam, col, data1);
            tt.put(t1, p);
         }
         tm.tryCommit(t1);

         TransactionState t2 = tm.beginTransaction();
         LOG.info("Transaction created " + t2);
         Delete d = new Delete(modrow);
         tt.delete(t2, d);

         ResultScanner rs = tt.getScanner(t2, new Scan());
         Result r = rs.next();
         count = 0;
         while (r != null) {
            count++;
            LOG.trace("row: " + Bytes.toString(r.getRow()) + " count: " + count);
            r = rs.next();
         }
         assertEquals("Wrong count", rowcount - 1, count);

         TransactionState t3 = tm.beginTransaction();
         LOG.info("Transaction created " + t3);
         Put p = new Put(modrow);
         p.add(fam, col, data2);
         tt.put(t3, p);

         tm.tryCommit(t3);

         boolean aborted = false;
         try {
            tm.tryCommit(t2);
            assertTrue("Didn't abort", false);
         } catch (CommitUnsuccessfulException e) {
            aborted = true;
         }
         assertTrue("Didn't raise exception", aborted);

         TransactionState tscan = tm.beginTransaction();
         rs = tt.getScanner(tscan, new Scan());
         r = rs.next();
         count = 0;
         while (r != null) {
            count++;
            r = rs.next();
View Full Code Here

   private static final Log LOG = LogFactory.getLog(TestAbortTransaction.class);

   @Test public void runTestInterleaveScan() throws Exception {
      try {
         TransactionManager tm = new TransactionManager(conf);
         TransactionalTable tt = new TransactionalTable(conf, TEST_TABLE);
        
         TransactionState t1 = tm.beginTransaction();
         LOG.info("Transaction created " + t1);
        
         byte[] fam = Bytes.toBytes(TEST_FAMILY);
         byte[] col = Bytes.toBytes("testdata");
         byte[] data1 = Bytes.toBytes("testWrite-1");
         byte[] data2 = Bytes.toBytes("testWrite-2");
        
         byte[] startrow = Bytes.toBytes("test-scan" + 0);
         byte[] stoprow = Bytes.toBytes("test-scan" + 9);
         byte[] modrow = Bytes.toBytes("test-scan" + 3);
         for (int i = 0; i < 10; i++) {
            byte[] row = Bytes.toBytes("test-scan" + i);
           
            Put p = new Put(row);
            p.add(fam, col, data1);
            tt.put(t1, p);
         }
         tm.tryCommit(t1);

         TransactionState t2 = tm.beginTransaction();
         Put p = new Put(modrow);
         p.add(fam, col, data2);
         tt.put(t2, p);        
        
         int modifiedrows = 0;
         ResultScanner rs = tt.getScanner(t2, new Scan().setStartRow(startrow).setStopRow(stoprow).addColumn(fam, col));
         Result r = rs.next();
         while (r != null) {
            if (Bytes.equals(data2, r.getValue(fam, col))) {
               if (LOG.isTraceEnabled()) {
                  LOG.trace("Modified :" + Bytes.toString(r.getRow()));
               }
               modifiedrows++;
            }
           
            r = rs.next();
         }
        
         assertTrue("Expected 1 row modified, but " + modifiedrows + " are.",
                    modifiedrows == 1);
         tm.abort(t2);
        
         TransactionState tscan = tm.beginTransaction();
         rs = tt.getScanner(tscan, new Scan().setStartRow(startrow).setStopRow(stoprow).addColumn(fam, col));
         r = rs.next();
         while (r != null) {
            if (LOG.isTraceEnabled()) {
               LOG.trace("Scan1 :" + Bytes.toString(r.getRow()) + " => " + Bytes.toString(r.getValue(fam, col)));
            }
View Full Code Here

   private static final Log LOG = LogFactory.getLog(TestNonexistentRow.class);

   @Test public void testMultiPutSameRow() throws Exception {
      try{
         TransactionManager tm = new TransactionManager(conf);
         TransactionalTable table1 = new TransactionalTable(conf, TEST_TABLE);

         int num=10;
         TransactionState t=tm.beginTransaction();
         for(int j=0;j<num;j++) {
            byte[]data=Bytes.toBytes(j);
            Put put=new Put(data);
            put.add(Bytes.toBytes(TEST_FAMILY), Bytes.toBytes("value"), data);
            table1.put(t,put);
         }
         int key=15;
         Get g=new Get(Bytes.toBytes(key));
         Result r=table1.get(t,g);
        
         assertTrue("Found a row that should not exist", r.isEmpty());

         tm.tryCommit(t);
      } catch (Exception e) {
View Full Code Here

   private static final Log LOG = LogFactory.getLog(TestCompaction.class);

   @Test public void testDeleteOld() throws Exception {
      try {
         TransactionManager tm = new TransactionManager(conf);
         TransactionalTable tt = new TransactionalTable(conf, TEST_TABLE);

         TransactionState t1 = tm.beginTransaction();
         LOG.info("Transaction created " + t1);

         byte[] row = Bytes.toBytes("test-simple");
         byte[] fam = Bytes.toBytes(TEST_FAMILY);
         byte[] col = Bytes.toBytes("testdata");
         byte[] col2 = Bytes.toBytes("testdata2");
         byte[] data1 = Bytes.toBytes("testWrite-1");
         byte[] data2 = Bytes.toBytes("testWrite-2verylargedatamuchmoredata than anything ever written to");

         Put p = new Put(row);
         p.add(fam, col, data1);
         tt.put(t1, p);
         tm.tryCommit(t1);

         TransactionState t2 = tm.beginTransaction();
         p = new Put(row);
         p.add(fam, col, data2);
         tt.put(t2, p);
         tm.tryCommit(t2);

         for (int i = 0; i < 500; ++i) {
            t2 = tm.beginTransaction();
            p = new Put(row);
            p.add(fam, col2, data2);
            tt.put(t2, p);
            tm.tryCommit(t2);
         }
        
         HBaseAdmin admin = new HBaseAdmin(conf);
         admin.flush(TEST_TABLE);
        
         for (int i = 0; i < 500; ++i) {
            t2 = tm.beginTransaction();
            p = new Put(row);
            p.add(fam, col2, data2);
            tt.put(t2, p);
            tm.tryCommit(t2);
         }

         Get g = new Get(row);
         g.setMaxVersions();
         g.addColumn(fam, col2);
         Result r = tt.get(g);
         int size = r.getColumn(fam, col2).size();
         LOG.info("Size before compaction : " + size);

         admin.compact(TEST_TABLE);
        
         Thread.sleep(2000);
        
         g = new Get(row);
         g.setMaxVersions();
         g.addColumn(fam, col);
         r = tt.get(g);
         assertEquals(1, r.getColumn(fam, col).size());
        
         g = new Get(row);
         g.setMaxVersions();
         g.addColumn(fam, col2);
         r = tt.get(g);
         LOG.info("Size after compaction " + r.getColumn(fam, col2).size());
         assertThat(r.getColumn(fam, col2).size(), is(lessThan(size)));
      } catch (Exception e) {
         LOG.error("Exception occurred", e);
         throw e;
View Full Code Here

   }

   @Test public void testLimitEqualToColumns() throws Exception {
      try {
         TransactionManager tm = new TransactionManager(conf);
         TransactionalTable tt = new TransactionalTable(conf, TEST_TABLE);

         TransactionState t1 = tm.beginTransaction();

         byte[] row = Bytes.toBytes("test-simple");
         byte[] row2 = Bytes.toBytes("test-simple2");
         byte[] row3 = Bytes.toBytes("test-simple3");
         byte[] row4 = Bytes.toBytes("test-simple4");
         byte[] fam = Bytes.toBytes(TEST_FAMILY);
         byte[] col = Bytes.toBytes("testdata");
         byte[] col1 = Bytes.add(col, Bytes.toBytes(1));
         byte[] col11 = Bytes.add(col, Bytes.toBytes(11));
         byte[] data = Bytes.toBytes("testWrite-1");
         byte[] data2 = Bytes.toBytes("testWrite-2verylargedatamuchmoredata than anything ever written to");

         Put p = new Put(row);
         for (int i = 0; i < 10; ++i) {
            p.add(fam, Bytes.add(col, Bytes.toBytes(i)), data);
         }
         tt.put(t1, p);
         tm.tryCommit(t1);

         TransactionState t2 = tm.beginTransaction();
         p = new Put(row2);
         for (int i = 0; i < 10; ++i) {
            p.add(fam, Bytes.add(col, Bytes.toBytes(i)), data);
         }
         tt.put(t2, p);
         tm.tryCommit(t2);

         // fill with data
         for (int i = 0; i < 500; ++i) {
            t2 = tm.beginTransaction();
            p = new Put(row4);
            p.add(fam, col11, data2);
            tt.put(t2, p);
            tm.tryCommit(t2);
         }

         HBaseAdmin admin = new HBaseAdmin(conf);
         admin.flush(TEST_TABLE);

         TransactionState t3 = tm.beginTransaction();
         p = new Put(row3);
         for (int i = 0; i < 10; ++i) {
            p.add(fam, Bytes.add(col, Bytes.toBytes(i)), data);
         }
         tt.put(t3, p);
         tm.tryCommit(t3);

         // fill with data
         for (int i = 0; i < 500; ++i) {
            t2 = tm.beginTransaction();
            p = new Put(row4);
            p.add(fam, col11, data2);
            tt.put(t2, p);
            tm.tryCommit(t2);
         }

         Get g = new Get(row);
         g.setMaxVersions();
         g.addColumn(fam, col1);
         Result r = tt.get(g);
         int size = r.getColumn(fam, col1).size();
         LOG.info("Size before compaction : " + size);

         admin.compact(TEST_TABLE);

         Thread.sleep(2000);

         Scan s = new Scan(row);
         s.setMaxVersions();
         s.addColumn(fam, col1);
         ResultScanner rs = tt.getScanner(s);
         int count = 0;
         while ((r = rs.next()) != null) {
            count += r.getColumn(fam, col1).size();
         }
         assertEquals(3, count);
View Full Code Here

   private static final String TEST_COL = "value";

   @Test public void testGet() throws Exception {
      try{
         TransactionManager tm = new TransactionManager(conf);
         TransactionalTable table = new TransactionalTable(conf, TEST_TABLE);
         TransactionState t=tm.beginTransaction();
         int[] lInts=new int[]{100,243,2342,22,1,5,43,56};
         for (int i=0;i<lInts.length;i++) {
            byte[]data=Bytes.toBytes(lInts[i]);
            Put put=new Put(data);
            put.add(Bytes.toBytes(TEST_FAMILY), Bytes.toBytes(TEST_COL), data);
            table.put(t,put);
         }
         int startKeyValue=lInts[3];
         int stopKeyValue=lInts[3];
         byte[] startKey=Bytes.toBytes(startKeyValue);
         byte[] stopKey=Bytes.toBytes(stopKeyValue);
         Get g=new Get(startKey);
         Result r=table.get(t,g);
         if (!r.isEmpty()) {
            int tmp=Bytes.toInt(r.getValue(Bytes.toBytes(TEST_FAMILY),
                                           Bytes.toBytes(TEST_COL)));
            LOG.info("Result:" + tmp);
            assertTrue("Bad value, should be "
                       + startKeyValue + " but is " + tmp
                       , tmp == startKeyValue);
         } else {
            fail("Bad result");
         }
         tm.tryCommit(t);

         Scan s=new Scan(startKey);
         CompareFilter.CompareOp op=CompareFilter.CompareOp.LESS_OR_EQUAL;
         RowFilter toFilter = new RowFilter(op, new BinaryPrefixComparator(stopKey));
         boolean startInclusive=true;
         if (!startInclusive)  {
            FilterList filters = new FilterList(FilterList.Operator.MUST_PASS_ALL);
            filters.addFilter(new RowFilter(CompareFilter.CompareOp.GREATER,
                                            new BinaryPrefixComparator(startKey)));
            filters.addFilter(new WhileMatchFilter(toFilter));
            s.setFilter(filters);
         } else {
            s.setFilter(new WhileMatchFilter(toFilter));
         }
         t=tm.beginTransaction();
         ResultScanner res=table.getScanner(t,s);
         Result rr;
         int count = 0;
         while ((rr=res.next())!=null) {
            int iTmp=Bytes.toInt(rr.getValue(Bytes.toBytes(TEST_FAMILY),
                                             Bytes.toBytes(TEST_COL)));
            LOG.info("Result: "+iTmp);
            count++;
         }
         assertEquals("Count is wrong", 1, count);
         LOG.info("Rows found " + count);
         tm.tryCommit(t);
         table.close();
      } catch (Exception e) {
         LOG.error("Exception in test", e);
      }
   }
View Full Code Here

   }

   @Test public void testScan() throws Exception {
      try{
         TransactionManager tm = new TransactionManager(conf);
         TransactionalTable table = new TransactionalTable(conf, TEST_TABLE);
         TransactionState t=tm.beginTransaction();
         int[] lInts=new int[]{100,243,2342,22,1,5,43,56};
         for (int i=0;i<lInts.length;i++) {
            byte[]data=Bytes.toBytes(lInts[i]);
            Put put=new Put(data);
            put.add(Bytes.toBytes(TEST_FAMILY), Bytes.toBytes(TEST_COL), data);
            table.put(t,put);
         }
        
         Scan s=new Scan();
         ResultScanner res=table.getScanner(t, s);
         Result rr;
         int count = 0;
         while ((rr=res.next())!=null) {
            int iTmp=Bytes.toInt(rr.getValue(Bytes.toBytes(TEST_FAMILY),
                                             Bytes.toBytes(TEST_COL)));
            LOG.info("Result: "+iTmp);
            count++;
         }
         assertTrue("Count should be " + lInts.length + " but is " + count,
                    count == lInts.length);
         LOG.info("Rows found " + count);

         tm.tryCommit(t);

         t=tm.beginTransaction();
         res=table.getScanner(t,s);
         count = 0;
         while ((rr=res.next())!=null) {
            int iTmp=Bytes.toInt(rr.getValue(Bytes.toBytes(TEST_FAMILY),
                                             Bytes.toBytes(TEST_COL)));
            LOG.info("Result: "+iTmp);
            count++;
         }
         assertTrue("Count should be " + lInts.length + " but is " + count,
                    count == lInts.length);
         LOG.info("Rows found " + count);
         tm.tryCommit(t);
         table.close();
      } catch (Exception e) {
         LOG.error("Exception in test", e);
      }
   }
View Full Code Here

  

   @Test public void testScanUncommitted() throws Exception {
      try{
         TransactionManager tm = new TransactionManager(conf);
         TransactionalTable table = new TransactionalTable(conf, TEST_TABLE);
         TransactionState t=tm.beginTransaction();
         int[] lIntsA=new int[]{100,243,2342,22,1,5,43,56};
         for (int i=0;i<lIntsA.length;i++) {
            byte[]data=Bytes.toBytes(lIntsA[i]);
            Put put=new Put(data);
            put.add(Bytes.toBytes(TEST_FAMILY), Bytes.toBytes(TEST_COL), data);
            table.put(t,put);
         }
         tm.tryCommit(t);
  
         TransactionState tu=tm.beginTransaction();
         int[] lIntsB=new int[]{105,24,4342,32,7,3,30,40};
         for (int i=0;i<lIntsB.length;i++) {
            byte[]data=Bytes.toBytes(lIntsB[i]);
            Put put=new Put(data);
            put.add(Bytes.toBytes(TEST_FAMILY), Bytes.toBytes(TEST_COL), data);
            table.put(tu,put);
         }
  
         t=tm.beginTransaction();
         int[] lIntsC=new int[]{109,224,242,2,16,59,23,26};
         for (int i=0;i<lIntsC.length;i++) {
            byte[]data=Bytes.toBytes(lIntsC[i]);
            Put put=new Put(data);
            put.add(Bytes.toBytes(TEST_FAMILY), Bytes.toBytes(TEST_COL), data);
            table.put(t,put);
         }
         tm.tryCommit(t);
        
         t=tm.beginTransaction();
         Scan s=new Scan();
         ResultScanner res=table.getScanner(t,s);
         Result rr;
         int count = 0;
  
         while ((rr=res.next())!=null) {
            int iTmp=Bytes.toInt(rr.getValue(Bytes.toBytes(TEST_FAMILY),
                                             Bytes.toBytes(TEST_COL)));
            LOG.info("Result: "+iTmp);
            count++;
         }
         assertTrue("Count should be " + (lIntsA.length*lIntsC.length) + " but is " + count,
                    count == lIntsA.length + lIntsC.length);
         LOG.info("Rows found " + count);
         tm.tryCommit(t);
         table.close();
      } catch (Exception e) {
         LOG.error("Exception in test", e);
      }
   }
View Full Code Here

TOP

Related Classes of com.yahoo.omid.client.TransactionalTable

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.