/** {@inheritDoc} */ @Override public void restoreKeyValuesFromBackup(final String tableName, KeyValueBackup keyValueBackup) throws IOException { LOG.debug(String.format("Restoring '%s' key-value(s) from backup for table '%s'.", keyValueBackup.getKeyValues().size(), tableName)); for (KeyValueBackupEntry kvRecord : keyValueBackup.getKeyValues()) { final byte[] key = Bytes.toBytes(kvRecord.getKey()); final ByteBuffer valueBuffer = kvRecord.getValue(); // Read in ByteBuffer of values byte[] value = new byte[valueBuffer.remaining()]; // Instantiate ByteArray valueBuffer.get(value); // Write buffer to array final long timestamp = kvRecord.getTimestamp(); LOG.debug(String.format("For the table '%s' we are writing to family '%s', qualifier '%s'" + ", timestamp '%s', and value '%s' to the" + " meta table named '%s'.", tableName, Bytes.toString(mFamilyBytes), Bytes.toString(key), "" + timestamp, Bytes.toString(value), Bytes.toString(mTable.getTableName()))); final Put put = new Put(Bytes.toBytes(tableName)).add(mFamilyBytes, key, timestamp, value); mTable.put(put); } LOG.debug("Flushing commits to restore key-values from backup."); mTable.flushCommits(); } }
/** {@inheritDoc} */ @Override public KeyValueBackup keyValuesToBackup(String table) throws IOException { final List<KeyValueBackupEntry> kvBackupEntries = Lists.newArrayList(); final Set<String> keys = keySet(table); for (String key : keys) { NavigableMap<Long, byte[]> versionedValues = getTimedValues(table, key, Integer.MAX_VALUE); for (Long timestamp : versionedValues.descendingKeySet()) { kvBackupEntries.add(KeyValueBackupEntry.newBuilder() .setKey(key) .setValue(ByteBuffer.wrap(versionedValues.get(timestamp))) .setTimestamp(timestamp) .build()); } } return KeyValueBackup.newBuilder().setKeyValues(kvBackupEntries).build(); }
/** {@inheritDoc} */ @Override public KeyValueBackup keyValuesToBackup(String table) throws IOException { List<KeyValueBackupEntry> kvBackupEntries = Lists.newArrayList(); final Set<String> keys = keySet(table); for (String key : keys) { NavigableMap<Long, byte[]> versionedValues = getTimedValues(table, key, Integer.MAX_VALUE); for (Long timestamp : versionedValues.descendingKeySet()) { kvBackupEntries.add(KeyValueBackupEntry.newBuilder() .setKey(key) .setValue(ByteBuffer.wrap(versionedValues.get(timestamp))) .setTimestamp(timestamp) .build()); } } KeyValueBackup kvBackup = KeyValueBackup.newBuilder().setKeyValues(kvBackupEntries).build(); return kvBackup; }
/** {@inheritDoc} */ @Override public void restoreKeyValuesFromBackup(final String tableName, KeyValueBackup keyValueBackup) throws IOException { LOG.debug("Restoring '{}' key-value(s) from backup for table '{}'.", keyValueBackup.getKeyValues().size(), tableName); for (KeyValueBackupEntry kvRecord : keyValueBackup.getKeyValues()) { final String key = kvRecord.getKey(); final ByteBuffer valAsByteBuffer = kvRecord.getValue(); // Read in ByteBuffer of values final long timestamp = kvRecord.getTimestamp(); LOG.debug("For the table '{}' we are writing key '{}', timestamp '{}', " + "and value '{}' to the metatable named '{}'.", tableName, key, timestamp, valAsByteBuffer.toString(), mTable); mAdmin.execute( mRestoreKeyValuesFromBackupStatement .bind(tableName, key, new Date(timestamp), valAsByteBuffer)); } LOG.debug("Flushing commits to restore key-values from backup."); // TODO: Any flush needed? //mTable.flushCommits(); } }