Package org.apache.hcatalog.hbase.snapshot

Examples of org.apache.hcatalog.hbase.snapshot.RevisionManager


  }

  private List<Put> generatePuts(int num, String tableName) throws IOException {

    List<String> columnFamilies = Arrays.asList("testFamily");
    RevisionManager rm = null;
    List<Put> myPuts;
    try {
      rm = HBaseRevisionManagerUtil.getOpenedRevisionManager(hcatConf);
      rm.open();
      myPuts = new ArrayList<Put>();
      for (int i = 1; i <= num; i++) {
        Put put = new Put(Bytes.toBytes("testRow"));
        put.add(FAMILY, QUALIFIER1, i, Bytes.toBytes("textValue-" + i));
        put.add(FAMILY, QUALIFIER2, i, Bytes.toBytes("textValue-" + i));
        myPuts.add(put);
        Transaction tsx = rm.beginWriteTransaction(tableName,
            columnFamilies);
        rm.commitWriteTransaction(tsx);
      }
    } finally {
      if (rm != null)
        rm.close();
    }

    return myPuts;
  }
View Full Code Here


  }

  private long populateHBaseTableQualifier1(String tName, int value, Boolean commit)
    throws IOException {
    List<String> columnFamilies = Arrays.asList("testFamily");
    RevisionManager rm = null;
    List<Put> myPuts = new ArrayList<Put>();
    long revision;
    try {
      rm = HBaseRevisionManagerUtil.getOpenedRevisionManager(hcatConf);
      rm.open();
      Transaction tsx = rm.beginWriteTransaction(tName, columnFamilies);

      Put put = new Put(Bytes.toBytes("testRow"));
      revision = tsx.getRevisionNumber();
      put.add(FAMILY, QUALIFIER1, revision,
          Bytes.toBytes("textValue-" + value));
      myPuts.add(put);

      // If commit is null it is left as a running transaction
      if (commit != null) {
        if (commit) {
          rm.commitWriteTransaction(tsx);
        } else {
          rm.abortWriteTransaction(tsx);
        }
      }
    } finally {
      if (rm != null)
        rm.close();
    }
    HTable table = new HTable(getHbaseConf(), Bytes.toBytes(tName));
    table.put(myPuts);
    return revision;
  }
View Full Code Here

    job.setOutputFormat(HBaseBulkOutputFormat.class);
    org.apache.hadoop.mapred.SequenceFileOutputFormat.setOutputPath(job, interPath);
    job.setOutputCommitter(HBaseBulkOutputCommitter.class);

    //manually create transaction
    RevisionManager rm = HBaseRevisionManagerUtil.getOpenedRevisionManager(conf);
    try {
      OutputJobInfo outputJobInfo = OutputJobInfo.create("default", tableName, null);
      Transaction txn = rm.beginWriteTransaction(tableName, Arrays.asList(familyName));
      outputJobInfo.getProperties().setProperty(HBaseConstants.PROPERTY_WRITE_TXN_KEY,
        HCatUtil.serialize(txn));
      job.set(HCatConstants.HCAT_KEY_OUTPUT_INFO,
        HCatUtil.serialize(outputJobInfo));
    } finally {
      rm.close();
    }

    job.setMapOutputKeyClass(ImmutableBytesWritable.class);
    job.setMapOutputValueClass(HCatRecord.class);
View Full Code Here

    job.setOutputValueClass(HCatRecord.class);

    job.setNumReduceTasks(0);

    assertTrue(job.waitForCompletion(true));
    RevisionManager rm = HBaseRevisionManagerUtil.getOpenedRevisionManager(conf);
    try {
      TableSnapshot snapshot = rm.createSnapshot(databaseName + "." + tableName);
      for (String el : snapshot.getColumnFamilies()) {
        assertEquals(1, snapshot.getRevision(el));
      }
    } finally {
      rm.close();
    }

    //verify
    HTable table = new HTable(conf, databaseName + "." + tableName);
    Scan scan = new Scan();
View Full Code Here

      conf, workingDir, MapWriteAbortTransaction.class,
      outputJobInfo, inputPath);
    assertFalse(job.waitForCompletion(true));

    // verify that revision manager has it as aborted transaction
    RevisionManager rm = HBaseRevisionManagerUtil.getOpenedRevisionManager(conf);
    try {
      TableSnapshot snapshot = rm.createSnapshot(databaseName + "." + tableName);
      for (String family : snapshot.getColumnFamilies()) {
        assertEquals(1, snapshot.getRevision(family));
        List<FamilyRevision> abortedWriteTransactions = rm.getAbortedWriteTransactions(
          databaseName + "." + tableName, family);
        assertEquals(1, abortedWriteTransactions.size());
        assertEquals(1, abortedWriteTransactions.get(0).getRevision());
      }
    } finally {
      rm.close();
    }

    //verify that hbase does not have any of the records.
    //Since records are only written during commitJob,
    //hbase should not have any records.
View Full Code Here

    job.setOutputFormat(HBaseDirectOutputFormat.class);
    job.set(TableOutputFormat.OUTPUT_TABLE, tableName);
    job.set(HBaseConstants.PROPERTY_OUTPUT_TABLE_NAME_KEY, tableName);

    //manually create transaction
    RevisionManager rm = HBaseRevisionManagerUtil.getOpenedRevisionManager(conf);
    try {
      OutputJobInfo outputJobInfo = OutputJobInfo.create("default", tableName, null);
      Transaction txn = rm.beginWriteTransaction(tableName, Arrays.asList(familyName));
      outputJobInfo.getProperties().setProperty(HBaseConstants.PROPERTY_WRITE_TXN_KEY,
        HCatUtil.serialize(txn));
      job.set(HCatConstants.HCAT_KEY_OUTPUT_INFO,
        HCatUtil.serialize(outputJobInfo));
    } finally {
      rm.close();
    }

    job.setMapOutputKeyClass(BytesWritable.class);
    job.setMapOutputValueClass(HCatRecord.class);
    job.setOutputKeyClass(BytesWritable.class);
View Full Code Here

      tableName, null);
    Job job = configureJob(testName, conf, workingDir, MapHCatWrite.class,
      outputJobInfo, inputPath);
    assertTrue(job.waitForCompletion(true));

    RevisionManager rm = HBaseRevisionManagerUtil.getOpenedRevisionManager(conf);
    try {
      TableSnapshot snapshot = rm.createSnapshot(hbaseTableName);
      for (String el : snapshot.getColumnFamilies()) {
        assertEquals(1, snapshot.getRevision(el));
      }
    } finally {
      rm.close();
    }

    //verify
    HTable table = new HTable(conf, hbaseTableName);
    Scan scan = new Scan();
View Full Code Here

    Job job = configureJob(testName, conf, workingDir, MapWriteAbortTransaction.class,
      outputJobInfo, inputPath);
    assertFalse(job.waitForCompletion(true));

    // verify that revision manager has it as aborted transaction
    RevisionManager rm = HBaseRevisionManagerUtil.getOpenedRevisionManager(conf);
    try {
      TableSnapshot snapshot = rm.createSnapshot(hbaseTableName);
      for (String family : snapshot.getColumnFamilies()) {
        assertEquals(1, snapshot.getRevision(family));
        List<FamilyRevision> abortedWriteTransactions = rm.getAbortedWriteTransactions(
          hbaseTableName, family);
        assertEquals(1, abortedWriteTransactions.size());
        assertEquals(1, abortedWriteTransactions.get(0).getRevision());
      }
    } finally {
      rm.close();
    }

    // verify that hbase has the records of the successful maps.
    HTable table = new HTable(conf, hbaseTableName);
    Scan scan = new Scan();
View Full Code Here

    HBaseAdmin hAdmin = new HBaseAdmin(getHbaseConf());
    boolean doesTableExist = hAdmin.tableExists("test_table");

    assertTrue(doesTableExist);

    RevisionManager rm = HBaseRevisionManagerUtil.getOpenedRevisionManager(hcatConf);
    rm.open();
    //Should be able to successfully query revision manager
    rm.getAbortedWriteTransactions("test_table", "cf1");

    hcatDriver.run("drop table test_table");
    doesTableExist = hAdmin.tableExists("test_table");
    assertTrue(doesTableExist == false);

    try {
      rm.getAbortedWriteTransactions("test_table", "cf1");
    } catch (Exception e) {
      assertTrue(e.getCause() instanceof NoNodeException);
    }
    rm.close();

  }
View Full Code Here

    HBaseAdmin hAdmin = new HBaseAdmin(getHbaseConf());
    boolean doesTableExist = hAdmin.tableExists("test_table");

    assertTrue(doesTableExist);

    RevisionManager rm = HBaseRevisionManagerUtil.getOpenedRevisionManager(hcatConf);
    rm.open();
    //Should be able to successfully query revision manager
    rm.getAbortedWriteTransactions("test_table", "cf1");

    hcatDriver.run("drop table test_table");
    doesTableExist = hAdmin.tableExists("test_table");
    assertTrue(doesTableExist == false);

    try {
      rm.getAbortedWriteTransactions("test_table", "cf1");
    } catch (Exception e) {
      assertTrue(e.getCause() instanceof NoNodeException);
    }
    rm.close();

  }
View Full Code Here

TOP

Related Classes of org.apache.hcatalog.hbase.snapshot.RevisionManager

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.