/** * Puts HTable back into the HBase table pool. * * @param hTable * HBase Table instance */ private void puthTable(HTableInterface hTable) throws IOException { hTablePool.putTable(hTable); }
/** * Puts HTable back into the HBase table pool. * * @param hTable * HBase Table instance */ private void puthTable(HTableInterface hTable) throws IOException { hTablePool.putTable(hTable); }
/** * Puts HTable back into the HBase table pool. * * @param hTable * HBase Table instance */ private void puthTable(HTableInterface hTable) throws IOException { hTablePool.putTable(hTable); }
private void flushDeletes(byte[] tableName, Queue<Delete> deletes) { HTableInterface table = pool.getTable(tableName); try { table.delete(new ArrayList<Delete>(deletes)); } catch (IOException e) { throw new RuntimeException(e); } finally { pool.putTable(table); } deletes.clear(); }
private void flushPuts(byte[] tableName, Queue<Put> puts) { HTableInterface table = pool.getTable(tableName); try { table.put(new ArrayList<Put>(puts)); } catch (IOException e) { throw new RuntimeException(e); } finally { pool.putTable(table); } puts.clear(); }
protected Result getResult(byte[] tableName, Get get) { HTableInterface table = pool.getTable(tableName); try { return table.get(get); } catch (IOException e) { throw new RuntimeException(e); } finally { pool.putTable(table); } }
/** * Take an htable from the pool, use it with the given HTableRunnable, and return it to * the pool. This is the "loan pattern" where the htable resource is used temporarily by * the runnable. */ public static <T> T run(HTablePool pool, byte[] tableName, HTableRunnable<T> runnable) throws IOException { HTableInterface hTable = null; try { hTable = pool.getTable(tableName); return runnable.runWith(hTable); } catch (Exception e) { if (e instanceof IOException) { throw (IOException) e; } else { throw new RuntimeException(e); } } finally { if (hTable != null) { pool.putTable(hTable); } } }
public long incrementColumnValue(ByteBuffer table, ByteBuffer row, ByteBuffer family, ByteBuffer qualifier, long amount, boolean writeToWAL) throws AIOError { HTableInterface htable = htablePool.getTable(Bytes.toBytes(table)); try { return htable.incrementColumnValue(Bytes.toBytes(row), Bytes.toBytes(family), Bytes.toBytes(qualifier), amount, writeToWAL); } catch (IOException e) { AIOError ioe = new AIOError(); ioe.message = new Utf8(e.getMessage()); throw ioe; } finally { try { htablePool.putTable(htable); } catch (IOException e) { AIOError ioe = new AIOError(); ioe.message = new Utf8(e.getMessage()); throw ioe; } } }
@Override public void delete(byte[] row) throws AvroBaseException { HTableInterface table = getTable(); try { Delete delete = new Delete(row); delete.deleteFamily(family); table.delete(delete); } catch (IOException e) { throw new AvroBaseException("Failed to delete row", e); } finally { pool.putTable(table); } }
@Override public boolean put(byte[] row, T value, long version) throws AvroBaseException { HTableInterface table = getTable(); try { Schema schema = value.getSchema(); String schemaKey = storeSchema(schema); byte[] bytes = serialize(value); Put put = new Put(row); put.add(family, SCHEMA_COLUMN, $(schemaKey)); put.add(family, DATA_COLUMN, bytes); put.add(family, VERSION_COLUMN, Bytes.toBytes(version + 1)); put.add(family, FORMAT_COLUMN, Bytes.toBytes(format.ordinal())); final byte[] expectedValue; if (version == 0) { expectedValue = new byte[0]; // TODO: should be null, but... HBASE-2920 } else { expectedValue = Bytes.toBytes(version); } return table.checkAndPut(row, family, VERSION_COLUMN, expectedValue, put); } catch (IOException e) { throw new AvroBaseException("Could not encode " + value, e); } finally { pool.putTable(table); } }
private String storeSchema(Schema schema) throws AvroBaseException { String schemaKey; synchronized (schema) { schemaKey = hashCache.get(schema); if (schemaKey == null) { // Hash the schema, store it String doc = schema.toString(); schemaKey = createSchemaKey(schema, doc); Put put = new Put($(schemaKey)); put.add(AVRO_FAMILY, SCHEMA_COLUMN, $(doc)); HTableInterface schemaTable = pool.getTable(schemaName); try { schemaTable.put(put); } catch (IOException e) { throw new AvroBaseException("Could not store schema " + doc, e); } finally { pool.putTable(schemaTable); } } } return schemaKey; }
public boolean exists(ByteBuffer table, AGet aget) throws AIOError { HTableInterface htable = htablePool.getTable(Bytes.toBytes(table)); try { return htable.exists(AvroUtil.agetToGet(aget)); } catch (IOException e) { AIOError ioe = new AIOError(); ioe.message = new Utf8(e.getMessage()); throw ioe; } finally { try { htablePool.putTable(htable); } catch (IOException e) { AIOError ioe = new AIOError(); ioe.message = new Utf8(e.getMessage()); throw ioe; } } }
@Override public Row<T, byte[]> get(byte[] row) throws AvroBaseException { HTableInterface table = getTable(); try { Result result = getHBaseRow(table, row, family); // TODO: This is working around a bug in HBASE 0.89 if (row.length == 0 && !Bytes.equals(row, result.getRow())) { return null; } return getRowResult(result, row); } catch (IOException e) { throw new AvroBaseException(e); } finally { pool.putTable(table); } }
public Void put(ByteBuffer table, APut aput) throws AIOError { HTableInterface htable = htablePool.getTable(Bytes.toBytes(table)); try { htable.put(AvroUtil.aputToPut(aput)); return null; } catch (IOException e) { AIOError ioe = new AIOError(); ioe.message = new Utf8(e.getMessage()); throw ioe; } finally { try { htablePool.putTable(htable); } catch (IOException e) { AIOError ioe = new AIOError(); ioe.message = new Utf8(e.getMessage()); throw ioe; } } }
public Void delete(ByteBuffer table, ADelete adelete) throws AIOError { HTableInterface htable = htablePool.getTable(Bytes.toBytes(table)); try { htable.delete(AvroUtil.adeleteToDelete(adelete)); return null; } catch (IOException e) { AIOError ioe = new AIOError(); ioe.message = new Utf8(e.getMessage()); throw ioe; } finally { try { htablePool.putTable(htable); } catch (IOException e) { AIOError ioe = new AIOError(); ioe.message = new Utf8(e.getMessage()); throw ioe; } } }
public AResult get(ByteBuffer table, AGet aget) throws AIOError { HTableInterface htable = htablePool.getTable(Bytes.toBytes(table)); try { return AvroUtil.resultToAResult(htable.get(AvroUtil.agetToGet(aget))); } catch (IOException e) { AIOError ioe = new AIOError(); ioe.message = new Utf8(e.getMessage()); throw ioe; } finally { try { htablePool.putTable(htable); } catch (IOException e) { AIOError ioe = new AIOError(); ioe.message = new Utf8(e.getMessage()); throw ioe; } } }
public int scannerOpen(ByteBuffer table, AScan ascan) throws AIOError { HTableInterface htable = htablePool.getTable(Bytes.toBytes(table)); try { Scan scan = AvroUtil.ascanToScan(ascan); return addScanner(htable.getScanner(scan)); } catch (IOException e) { AIOError ioe = new AIOError(); ioe.message = new Utf8(e.getMessage()); throw ioe; } finally { try { htablePool.putTable(htable); } catch (IOException e) { AIOError ioe = new AIOError(); ioe.message = new Utf8(e.getMessage()); throw ioe; } } }
@Override public void put(byte[] row, T value) throws AvroBaseException { HTableInterface table = getTable(); long version; try { do { // FIXME: Spin until success, last one wins. Provably dangerous? version = getVersion(family, row, table); } while (!put(row, value, version)); } catch (IOException e) { throw new AvroBaseException("Failed to retrieve version for row: " + $_(row), e); } finally { pool.putTable(table); } }
private Schema loadSchema(final byte[] row, final byte[] schemaKey, int offset, int length) throws AvroBaseException, IOException { if (schemaKey == null) { throw new AvroBaseException("Schema not set for row: " + $_(row)); } Schema schema = schemaCache.get($_(schemaKey, offset, length)); if (schema == null) { HTableInterface schemaTable = pool.getTable(schemaName); try { Get schemaGet = new Get(schemaKey); schemaGet.addColumn(AVRO_FAMILY, SCHEMA_COLUMN); byte[] schemaBytes = schemaTable.get(schemaGet).getValue(AVRO_FAMILY, SCHEMA_COLUMN); if (schemaBytes == null) { throw new AvroBaseException("No schema " + $_(schemaKey) + " found in hbase for row " + $_(row)); } schema = loadSchema(schemaBytes, $_(schemaKey)); } finally { pool.putTable(schemaTable); } } return schema; }