use of org.apache.phoenix.cache.IndexMetaDataCache in project phoenix by apache.
the class MutationState method newTxIndexMutationGenerator.
private PhoenixTxIndexMutationGenerator newTxIndexMutationGenerator(PTable table, List<PTable> indexes, Map<String, byte[]> attributes) {
final List<IndexMaintainer> indexMaintainers = Lists.newArrayListWithExpectedSize(indexes.size());
for (PTable index : indexes) {
IndexMaintainer maintainer = index.getIndexMaintainer(table, connection);
indexMaintainers.add(maintainer);
}
IndexMetaDataCache indexMetaDataCache = new IndexMetaDataCache() {
@Override
public void close() throws IOException {
}
@Override
public List<IndexMaintainer> getIndexMaintainers() {
return indexMaintainers;
}
@Override
public PhoenixTransactionContext getTransactionContext() {
return phoenixTransactionContext;
}
@Override
public int getClientVersion() {
return MetaDataProtocol.PHOENIX_VERSION;
}
};
try {
PhoenixIndexMetaData indexMetaData = new PhoenixIndexMetaData(indexMetaDataCache, attributes);
return new PhoenixTxIndexMutationGenerator(connection.getQueryServices().getConfiguration(), indexMetaData, table.getPhysicalName().getBytes());
} catch (IOException e) {
// Impossible
throw new RuntimeException(e);
}
}
use of org.apache.phoenix.cache.IndexMetaDataCache in project phoenix by apache.
the class PhoenixIndexMetaData method getIndexMetaData.
private static IndexMetaDataCache getIndexMetaData(RegionCoprocessorEnvironment env, Map<String, byte[]> attributes) throws IOException {
if (attributes == null) {
return IndexMetaDataCache.EMPTY_INDEX_META_DATA_CACHE;
}
byte[] uuid = attributes.get(PhoenixIndexCodec.INDEX_UUID);
if (uuid == null) {
return IndexMetaDataCache.EMPTY_INDEX_META_DATA_CACHE;
}
boolean useProto = false;
byte[] md = attributes.get(PhoenixIndexCodec.INDEX_PROTO_MD);
useProto = md != null;
if (md == null) {
md = attributes.get(PhoenixIndexCodec.INDEX_MD);
}
byte[] txState = attributes.get(BaseScannerRegionObserver.TX_STATE);
if (md != null) {
final List<IndexMaintainer> indexMaintainers = IndexMaintainer.deserialize(md, useProto);
final Transaction txn = MutationState.decodeTransaction(txState);
return new IndexMetaDataCache() {
@Override
public void close() throws IOException {
}
@Override
public List<IndexMaintainer> getIndexMaintainers() {
return indexMaintainers;
}
@Override
public Transaction getTransaction() {
return txn;
}
};
} else {
byte[] tenantIdBytes = attributes.get(PhoenixRuntime.TENANT_ID_ATTRIB);
ImmutableBytesPtr tenantId = tenantIdBytes == null ? null : new ImmutableBytesPtr(tenantIdBytes);
TenantCache cache = GlobalCache.getTenantCache(env, tenantId);
IndexMetaDataCache indexCache = (IndexMetaDataCache) cache.getServerCache(new ImmutableBytesPtr(uuid));
if (indexCache == null) {
String msg = "key=" + ServerCacheClient.idToString(uuid) + " region=" + env.getRegion() + "host=" + env.getRegionServerServices().getServerName();
SQLException e = new SQLExceptionInfo.Builder(SQLExceptionCode.INDEX_METADATA_NOT_FOUND).setMessage(msg).build().buildException();
// will not return
ServerUtil.throwIOException("Index update failed", e);
}
return indexCache;
}
}
use of org.apache.phoenix.cache.IndexMetaDataCache in project phoenix by apache.
the class IndexMetaDataCacheFactory method newCache.
@Override
public Closeable newCache(ImmutableBytesWritable cachePtr, byte[] txState, final MemoryChunk chunk, boolean useProtoForIndexMaintainer) throws SQLException {
// just use the standard keyvalue builder - this doesn't really need to be fast
final List<IndexMaintainer> maintainers = IndexMaintainer.deserialize(cachePtr, GenericKeyValueBuilder.INSTANCE, useProtoForIndexMaintainer);
final Transaction txn;
try {
txn = txState.length != 0 ? MutationState.decodeTransaction(txState) : null;
} catch (IOException e) {
throw new SQLException(e);
}
return new IndexMetaDataCache() {
@Override
public void close() throws IOException {
chunk.close();
}
@Override
public List<IndexMaintainer> getIndexMaintainers() {
return maintainers;
}
@Override
public Transaction getTransaction() {
return txn;
}
};
}
use of org.apache.phoenix.cache.IndexMetaDataCache in project phoenix by apache.
the class PhoenixIndexMetaDataBuilder method getIndexMetaDataCache.
private static IndexMetaDataCache getIndexMetaDataCache(RegionCoprocessorEnvironment env, Map<String, byte[]> attributes) throws IOException {
if (attributes == null) {
return IndexMetaDataCache.EMPTY_INDEX_META_DATA_CACHE;
}
byte[] uuid = attributes.get(PhoenixIndexCodec.INDEX_UUID);
if (uuid == null) {
return IndexMetaDataCache.EMPTY_INDEX_META_DATA_CACHE;
}
byte[] md = attributes.get(PhoenixIndexCodec.INDEX_PROTO_MD);
if (md == null) {
md = attributes.get(PhoenixIndexCodec.INDEX_MD);
}
if (md != null) {
boolean useProto = md != null;
byte[] txState = attributes.get(BaseScannerRegionObserver.TX_STATE);
final List<IndexMaintainer> indexMaintainers = IndexMaintainer.deserialize(md, useProto);
final PhoenixTransactionContext txnContext = TransactionFactory.getTransactionProvider().getTransactionContext(txState);
byte[] clientVersionBytes = attributes.get(PhoenixIndexCodec.CLIENT_VERSION);
final int clientVersion = clientVersionBytes == null ? IndexMetaDataCache.UNKNOWN_CLIENT_VERSION : Bytes.toInt(clientVersionBytes);
return new IndexMetaDataCache() {
@Override
public void close() throws IOException {
}
@Override
public List<IndexMaintainer> getIndexMaintainers() {
return indexMaintainers;
}
@Override
public PhoenixTransactionContext getTransactionContext() {
return txnContext;
}
@Override
public int getClientVersion() {
return clientVersion;
}
};
} else {
byte[] tenantIdBytes = attributes.get(PhoenixRuntime.TENANT_ID_ATTRIB);
ImmutableBytesPtr tenantId = tenantIdBytes == null ? null : new ImmutableBytesPtr(tenantIdBytes);
TenantCache cache = GlobalCache.getTenantCache(env, tenantId);
IndexMetaDataCache indexCache = (IndexMetaDataCache) cache.getServerCache(new ImmutableBytesPtr(uuid));
if (indexCache == null) {
String msg = "key=" + ServerCacheClient.idToString(uuid) + " region=" + env.getRegion() + "host=" + env.getRegionServerServices().getServerName();
SQLException e = new SQLExceptionInfo.Builder(SQLExceptionCode.INDEX_METADATA_NOT_FOUND).setMessage(msg).build().buildException();
// will not return
ServerUtil.throwIOException("Index update failed", e);
}
return indexCache;
}
}
use of org.apache.phoenix.cache.IndexMetaDataCache in project phoenix by apache.
the class IndexMetaDataCacheFactory method newCache.
@Override
public Closeable newCache(ImmutableBytesWritable cachePtr, byte[] txState, final MemoryChunk chunk, boolean useProtoForIndexMaintainer, final int clientVersion) throws SQLException {
// just use the standard keyvalue builder - this doesn't really need to be fast
final List<IndexMaintainer> maintainers = IndexMaintainer.deserialize(cachePtr, GenericKeyValueBuilder.INSTANCE, useProtoForIndexMaintainer);
final PhoenixTransactionContext txnContext;
try {
txnContext = txState.length != 0 ? TransactionFactory.getTransactionProvider().getTransactionContext(txState) : null;
} catch (IOException e) {
throw new SQLException(e);
}
return new IndexMetaDataCache() {
@Override
public void close() throws IOException {
chunk.close();
}
@Override
public List<IndexMaintainer> getIndexMaintainers() {
return maintainers;
}
@Override
public PhoenixTransactionContext getTransactionContext() {
return txnContext;
}
@Override
public int getClientVersion() {
return clientVersion;
}
};
}
Aggregations