use of org.apache.phoenix.hbase.index.util.ImmutableBytesPtr in project phoenix by apache.
the class PhoenixIndexPartialBuildMapper method setup.
@Override
protected void setup(final Context context) throws IOException, InterruptedException {
super.setup(context);
final Configuration configuration = context.getConfiguration();
writer = new DirectHTableWriter(configuration);
try {
final Properties overrideProps = new Properties();
String scn = configuration.get(PhoenixConfigurationUtil.CURRENT_SCN_VALUE);
String txScnValue = configuration.get(PhoenixConfigurationUtil.TX_SCN_VALUE);
if (txScnValue == null && scn != null) {
overrideProps.put(PhoenixRuntime.CURRENT_SCN_ATTRIB, scn);
}
connection = ConnectionUtil.getOutputConnection(configuration, overrideProps).unwrap(PhoenixConnection.class);
connection.setAutoCommit(false);
// Get BatchSize
ConnectionQueryServices services = connection.getQueryServices();
int maxSize = services.getProps().getInt(QueryServices.MAX_MUTATION_SIZE_ATTRIB, QueryServicesOptions.DEFAULT_MAX_MUTATION_SIZE);
batchSize = Math.min(connection.getMutateBatchSize(), maxSize);
LOG.info("Mutation Batch Size = " + batchSize);
this.mutations = Lists.newArrayListWithExpectedSize(batchSize);
maintainers = new ImmutableBytesPtr(PhoenixConfigurationUtil.getIndexMaintainers(configuration));
} catch (SQLException e) {
throw new RuntimeException(e.getMessage());
}
}
use of org.apache.phoenix.hbase.index.util.ImmutableBytesPtr in project phoenix by apache.
the class TupleUtil method getConcatenatedValue.
/** Concatenate results evaluated against a list of expressions
*
* @param result the tuple for expression evaluation
* @param expressions
* @return the concatenated byte array as ImmutableBytesWritable
* @throws IOException
*/
public static ImmutableBytesPtr getConcatenatedValue(Tuple result, List<Expression> expressions) throws IOException {
ImmutableBytesPtr value = new ImmutableBytesPtr(ByteUtil.EMPTY_BYTE_ARRAY);
Expression expression = expressions.get(0);
boolean evaluated = expression.evaluate(result, value);
if (expressions.size() == 1) {
if (!evaluated) {
value.set(ByteUtil.EMPTY_BYTE_ARRAY);
}
return value;
} else {
TrustedByteArrayOutputStream output = new TrustedByteArrayOutputStream(value.getLength() * expressions.size());
try {
if (evaluated) {
output.write(value.get(), value.getOffset(), value.getLength());
}
for (int i = 1; i < expressions.size(); i++) {
if (!expression.getDataType().isFixedWidth()) {
output.write(SchemaUtil.getSeparatorByte(true, value.getLength() == 0, expression));
}
expression = expressions.get(i);
if (expression.evaluate(result, value)) {
output.write(value.get(), value.getOffset(), value.getLength());
} else if (i < expressions.size() - 1 && expression.getDataType().isFixedWidth()) {
// converted to a variable length type (i.e. DECIMAL) to allow an empty byte array to represent null.
throw new DoNotRetryIOException("Non terminating null value found for fixed width expression (" + expression + ") in row: " + result);
}
}
// Write trailing separator if last expression was variable length and descending
if (!expression.getDataType().isFixedWidth() && SchemaUtil.getSeparatorByte(true, value.getLength() == 0, expression) == QueryConstants.DESC_SEPARATOR_BYTE) {
output.write(QueryConstants.DESC_SEPARATOR_BYTE);
}
byte[] outputBytes = output.getBuffer();
value.set(outputBytes, 0, output.size());
return value;
} finally {
output.close();
}
}
}
use of org.apache.phoenix.hbase.index.util.ImmutableBytesPtr in project phoenix by apache.
the class TenantCacheTest method testInvalidateClosesMemoryChunk.
@Test
public void testInvalidateClosesMemoryChunk() throws SQLException {
int maxServerCacheTimeToLive = 10000;
long maxBytes = 1000;
int maxWaitMs = 1000;
GlobalMemoryManager memoryManager = new GlobalMemoryManager(maxBytes, maxWaitMs);
TenantCacheImpl newTenantCache = new TenantCacheImpl(memoryManager, maxServerCacheTimeToLive);
ImmutableBytesPtr cacheId = new ImmutableBytesPtr(Bytes.toBytes("a"));
ImmutableBytesWritable cachePtr = new ImmutableBytesWritable(Bytes.toBytes("a"));
newTenantCache.addServerCache(cacheId, cachePtr, ByteUtil.EMPTY_BYTE_ARRAY, cacheFactory, true);
assertEquals(maxBytes - 1, memoryManager.getAvailableMemory());
newTenantCache.removeServerCache(cacheId);
assertEquals(maxBytes, memoryManager.getAvailableMemory());
}
use of org.apache.phoenix.hbase.index.util.ImmutableBytesPtr in project phoenix by apache.
the class TestNonTxIndexBuilder method getMultipleVersionMutation.
private MultiMutation getMultipleVersionMutation(int versions) {
MultiMutation mutation = new MultiMutation(new ImmutableBytesPtr(ROW));
for (int i = versions - 1; i >= 0; i--) {
Put put = new Put(ROW);
put.addImmutable(FAM, INDEXED_QUALIFIER, i, Bytes.toBytes(i));
mutation.addAll(put);
}
return mutation;
}
use of org.apache.phoenix.hbase.index.util.ImmutableBytesPtr in project phoenix by apache.
the class TestNonTxIndexBuilder method testRebuildMultipleVersionRow.
/**
* Tests a partial rebuild of a row with multiple versions. 3 versions of the row in data table,
* and we rebuild the index starting from time t=2
*
* There should be one index row version per data row version.
*/
@Test
public void testRebuildMultipleVersionRow() throws IOException {
// when doing a rebuild, we are replaying mutations so we want to ignore newer mutations
// see LocalTable#getCurrentRowState()
Mockito.when(mockIndexMetaData.ignoreNewerMutations()).thenReturn(true);
// the current row state has 3 versions, but if we rebuild as of t=2, scanner in LocalTable
// should only return first
Cell currentCell1 = CellUtil.createCell(ROW, FAM, INDEXED_QUALIFIER, 1, PUT_TYPE, VALUE_1);
Cell currentCell2 = CellUtil.createCell(ROW, FAM, INDEXED_QUALIFIER, 2, PUT_TYPE, VALUE_2);
Cell currentCell3 = CellUtil.createCell(ROW, FAM, INDEXED_QUALIFIER, 3, PUT_TYPE, VALUE_3);
Cell currentCell4 = CellUtil.createCell(ROW, FAM, INDEXED_QUALIFIER, 4, PUT_TYPE, VALUE_4);
setCurrentRowState(Arrays.asList(currentCell4, currentCell3, currentCell2, currentCell1));
// rebuilder replays mutations starting from t=2
MultiMutation mutation = new MultiMutation(new ImmutableBytesPtr(ROW));
Put put = new Put(ROW);
put.addImmutable(FAM, INDEXED_QUALIFIER, 4, VALUE_4);
mutation.addAll(put);
put = new Put(ROW);
put.addImmutable(FAM, INDEXED_QUALIFIER, 3, VALUE_3);
mutation.addAll(put);
put = new Put(ROW);
put.addImmutable(FAM, INDEXED_QUALIFIER, 2, VALUE_2);
mutation.addAll(put);
Collection<Pair<Mutation, byte[]>> indexUpdates = indexBuilder.getIndexUpdate(mutation, mockIndexMetaData);
// 3 puts and 3 deletes (one to hide existing index row for VALUE_1, and two to hide index
// rows for VALUE_2, VALUE_3)
assertEquals(6, indexUpdates.size());
assertContains(indexUpdates, 2, ROW, KeyValue.Type.DeleteFamily, FAM, new byte[0], /* qual not needed */
2);
assertContains(indexUpdates, ColumnTracker.NO_NEWER_PRIMARY_TABLE_ENTRY_TIMESTAMP, ROW, KeyValue.Type.Put, FAM, QueryConstants.EMPTY_COLUMN_BYTES, 2);
assertContains(indexUpdates, 3, ROW, KeyValue.Type.DeleteFamily, FAM, new byte[0], /* qual not needed */
3);
assertContains(indexUpdates, ColumnTracker.NO_NEWER_PRIMARY_TABLE_ENTRY_TIMESTAMP, ROW, KeyValue.Type.Put, FAM, QueryConstants.EMPTY_COLUMN_BYTES, 3);
assertContains(indexUpdates, 4, ROW, KeyValue.Type.DeleteFamily, FAM, new byte[0], /* qual not needed */
4);
assertContains(indexUpdates, ColumnTracker.NO_NEWER_PRIMARY_TABLE_ENTRY_TIMESTAMP, ROW, KeyValue.Type.Put, FAM, QueryConstants.EMPTY_COLUMN_BYTES, 4);
}
Aggregations