Java Code Examples for org.apache.hadoop.hbase.client.HTableInterface#flushCommits()

The following examples show how to use org.apache.hadoop.hbase.client.HTableInterface#flushCommits() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: QueryService.java    From Kylin with Apache License 2.0 6 votes vote down vote up
public void saveQuery(final String creator, final Query query) throws IOException {
    List<Query> queries = getQueries(creator);
    queries.add(query);
    Query[] queryArray = new Query[queries.size()];

    byte[] bytes = querySerializer.serialize(queries.toArray(queryArray));
    HTableInterface htable = null;
    try {
        htable = HBaseConnection.get(hbaseUrl).getTable(userTableName);
        Put put = new Put(Bytes.toBytes(creator));
        put.add(Bytes.toBytes(USER_QUERY_FAMILY), Bytes.toBytes(USER_QUERY_COLUMN), bytes);

        htable.put(put);
        htable.flushCommits();
    } finally {
        IOUtils.closeQuietly(htable);
    }
}
 
Example 2
Source File: AclService.java    From Kylin with Apache License 2.0 6 votes vote down vote up
@Override
public void deleteAcl(ObjectIdentity objectIdentity, boolean deleteChildren) throws ChildrenExistException {
    HTableInterface htable = null;
    try {
        htable = HBaseConnection.get(hbaseUrl).getTable(aclTableName);
        Delete delete = new Delete(Bytes.toBytes(String.valueOf(objectIdentity.getIdentifier())));

        List<ObjectIdentity> children = findChildren(objectIdentity);
        if (!deleteChildren && children.size() > 0) {
            throw new ChildrenExistException("Children exists for " + objectIdentity);
        }

        for (ObjectIdentity oid : children) {
            deleteAcl(oid, deleteChildren);
        }

        htable.delete(delete);
        htable.flushCommits();

        logger.debug("ACL of " + objectIdentity + " deleted successfully.");
    } catch (IOException e) {
        throw new RuntimeException(e.getMessage(), e);
    } finally {
        IOUtils.closeQuietly(htable);
    }
}
 
Example 3
Source File: UserService.java    From Kylin with Apache License 2.0 6 votes vote down vote up
@Override
public void updateUser(UserDetails user) {
    HTableInterface htable = null;
    try {
        byte[] userAuthorities = serialize(user.getAuthorities());
        htable = HBaseConnection.get(hbaseUrl).getTable(userTableName);
        Put put = new Put(Bytes.toBytes(user.getUsername()));
        put.add(Bytes.toBytes(USER_AUTHORITY_FAMILY), Bytes.toBytes(USER_AUTHORITY_COLUMN), userAuthorities);

        htable.put(put);
        htable.flushCommits();
    } catch (IOException e) {
        throw new RuntimeException(e.getMessage(), e);
    } finally {
        IOUtils.closeQuietly(htable);
    }
}
 
Example 4
Source File: HBaseResourceStore.java    From Kylin with Apache License 2.0 6 votes vote down vote up
@Override
protected void putResourceImpl(String resPath, InputStream content, long ts) throws IOException {
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    IOUtils.copy(content, bout);
    bout.close();

    HTableInterface table = getConnection().getTable(getAllInOneTableName());
    try {
        byte[] row = Bytes.toBytes(resPath);
        Put put = buildPut(resPath, ts, row, bout.toByteArray(), table);

        table.put(put);
        table.flushCommits();
    } finally {
        IOUtils.closeQuietly(table);
    }
}
 
Example 5
Source File: HBaseResourceStore.java    From Kylin with Apache License 2.0 6 votes vote down vote up
@Override
protected long checkAndPutResourceImpl(String resPath, byte[] content, long oldTS, long newTS) throws IOException, IllegalStateException {
    HTableInterface table = getConnection().getTable(getAllInOneTableName());
    try {
        byte[] row = Bytes.toBytes(resPath);
        byte[] bOldTS = oldTS == 0 ? null : Bytes.toBytes(oldTS);
        Put put = buildPut(resPath, newTS, row, content, table);

        boolean ok = table.checkAndPut(row, B_FAMILY, B_COLUMN_TS, bOldTS, put);
        if (!ok)
            throw new IllegalStateException("Overwriting conflict " + resPath + ", expect old TS " + oldTS + ", but it is " + getResourceTimestamp(resPath));

        table.flushCommits();

        return newTS;
    } finally {
        IOUtils.closeQuietly(table);
    }
}
 
Example 6
Source File: HBaseMetricSendClient.java    From jstorm with Apache License 2.0 6 votes vote down vote up
protected boolean batchAdd(Collection<KVSerializable> items, String tableName) {
    int size = items.size();
    List<Put> batch = new ArrayList<>(size);
    HTableInterface table = getHTableInterface(tableName);
    for (KVSerializable v : items) {
        byte[] rowKey = v.getKey();
        Put put = new Put(rowKey);
        put.add(CF, V_DATA, v.getValue());
        batch.add(put);
    }
    try {
        table.put(batch);
        table.flushCommits();
        succCounter.update(size);
        hbaseSendTps.update(size);
    } catch (Throwable ex) {
        logger.error("Error", ex);
        failedCounter.update(size);
        return false;
    } finally {
        closeTable(table);
    }
    return true;
}
 
Example 7
Source File: HBaseMetricSendClient.java    From jstorm with Apache License 2.0 6 votes vote down vote up
protected boolean add(KVSerializable item, String tableName) {
    long size = 1L;

    Put put = new Put(item.getKey());
    HTableInterface table = getHTableInterface(tableName);

    //put.setWriteToWAL(false);
    put.add(CF, V_DATA, item.getValue());
    try {
        table.put(put);
        table.flushCommits();
        succCounter.update(size);
        hbaseSendTps.update(size);
    } catch (Throwable ex) {
        logger.error("Error", ex);
        failedCounter.update(size);
        return false;
    } finally {
        closeTable(table);
    }
    return true;
}
 
Example 8
Source File: HBaseFactoryTest.java    From bigdata-tutorial with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

		String quorum = "192.168.0.30,192.168.0.31,192.168.0.32";
		quorum = "192.168.8.191,192.168.1.192,192.168.1.193";
		int port = 2181;
		HBaseFactoryTest factory = new HBaseFactoryTest(quorum, port);

		String tableName = "demo_test";
		String columnFamily = "cf";

		System.out.println("=============================== : create");
		factory.createTable(tableName, columnFamily);
		System.out.println("=============================== : print");
		factory.printTableDesc(tableName);
		System.out.println("=============================== : put");
		HTableInterface table = factory.getTable(tableName);
		table.setAutoFlushTo(false);
		for (int i = 0; i < 10; i++) {
			putCell(table, "rowkey" + i, columnFamily, "info", "micmiu-" + i);
		}
		table.flushCommits();
		table.close();

		System.out.println("=============================== : query");
		ResultScanner rs = HBaseFactoryTest.scanAll(table);
		for (Result result : rs) {
			System.out.println(">>>> result Empty : " + result.isEmpty());
			for (Cell cell : result.rawCells()) {
				System.out.print(">>>> cell rowkey= " + new String(CellUtil.cloneRow(cell)));
				System.out.print(",family= " + new String(CellUtil.cloneFamily(cell)) + ":" + new String(CellUtil.cloneQualifier(cell)));
				System.out.println(", value= " + new String(CellUtil.cloneValue(cell)));
			}
		}

		System.out.println("=============================== : delete");
		factory.deleteTable(tableName);

		factory.closeConn();
	}
 
Example 9
Source File: MappingTableDataTypeIT.java    From phoenix with Apache License 2.0 5 votes vote down vote up
private void insertData(final byte[] tableName, HBaseAdmin admin, HTableInterface t) throws IOException,
        InterruptedException {
    Put p = new Put(Bytes.toBytes("row"));
    p.add(Bytes.toBytes("cf"), Bytes.toBytes("q1"), Bytes.toBytes("value1"));
    t.put(p);
    t.flushCommits();
    admin.flush(tableName);
}
 
Example 10
Source File: JMeterHTablePool.java    From learning-hadoop with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
public synchronized void flush(String tableName) throws IOException {
  HTableInterface hTable = tablePool.getTable(tableName);
  try {
    hTable.flushCommits();
  } finally {
    if (hTable != null) {
      tablePool.putTable(hTable);
    }
  }
}
 
Example 11
Source File: QueryService.java    From Kylin with Apache License 2.0 5 votes vote down vote up
public void removeQuery(final String creator, final String id) throws IOException {
    List<Query> queries = getQueries(creator);
    Iterator<Query> queryIter = queries.iterator();

    boolean changed = false;
    while (queryIter.hasNext()) {
        Query temp = queryIter.next();
        if (temp.getId().equals(id)) {
            queryIter.remove();
            changed = true;
            break;
        }
    }

    if (!changed) {
        return;
    }

    Query[] queryArray = new Query[queries.size()];
    byte[] bytes = querySerializer.serialize(queries.toArray(queryArray));
    HTableInterface htable = null;
    try {
        htable = HBaseConnection.get(hbaseUrl).getTable(userTableName);
        Put put = new Put(Bytes.toBytes(creator));
        put.add(Bytes.toBytes(USER_QUERY_FAMILY), Bytes.toBytes(USER_QUERY_COLUMN), bytes);

        htable.put(put);
        htable.flushCommits();
    } finally {
        IOUtils.closeQuietly(htable);
    }
}
 
Example 12
Source File: UserService.java    From Kylin with Apache License 2.0 5 votes vote down vote up
@Override
public void deleteUser(String username) {
    HTableInterface htable = null;
    try {
        htable = HBaseConnection.get(hbaseUrl).getTable(userTableName);
        Delete delete = new Delete(Bytes.toBytes(username));

        htable.delete(delete);
        htable.flushCommits();
    } catch (IOException e) {
        throw new RuntimeException(e.getMessage(), e);
    } finally {
        IOUtils.closeQuietly(htable);
    }
}
 
Example 13
Source File: HBaseResourceStore.java    From Kylin with Apache License 2.0 5 votes vote down vote up
@Override
protected void deleteResourceImpl(String resPath) throws IOException {
    HTableInterface table = getConnection().getTable(getAllInOneTableName());
    try {
        Delete del = new Delete(Bytes.toBytes(resPath));
        table.delete(del);
        table.flushCommits();
    } finally {
        IOUtils.closeQuietly(table);
    }
}