phoenix-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ramkrish86 <...@git.apache.org>
Subject [GitHub] phoenix pull request: Phoenix-180
Date Thu, 11 Sep 2014 09:06:53 GMT
Github user ramkrish86 commented on a diff in the pull request:

    https://github.com/apache/phoenix/pull/12#discussion_r17410886
  
    --- Diff: phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
---
    @@ -1671,4 +1787,68 @@ private boolean allViewsInMultipleRegions() {
                 return results.size() > 0 && allViewsNotInSingleRegion;
             }
         }
    +
    +    /**
    +     * 
    +     * Matches rows that end with a given byte array suffix
    +     *
    +     * 
    +     * @since 3.0
    +     */
    +    private static class SuffixFilter extends FilterBase {
    +        protected byte[] suffix = null;
    +
    +        public SuffixFilter(final byte[] suffix) {
    +            this.suffix = suffix;
    +        }
    +        
    +        @Override
    +        public ReturnCode filterKeyValue(Cell ignored) throws IOException {
    +          return ReturnCode.INCLUDE;
    +        }
    +        
    +        @Override
    +        public boolean filterRowKey(byte[] buffer, int offset, int length) {
    +            if (buffer == null || this.suffix == null) return true;
    +            if (length < suffix.length) return true;
    +            // if they are equal, return false => pass row
    +            // else return true, filter row
    +            // if we are passed the suffix, set flag
    +            int cmp = Bytes.compareTo(buffer, offset + (length - this.suffix.length),
    +                    this.suffix.length, this.suffix, 0, this.suffix.length);
    +            return cmp != 0;
    +        }
    +    }
    +    
    +    @Override
    +    public void clearCacheForTable(RpcController controller, ClearCacheForTableRequest
request,
    +            RpcCallback<ClearCacheForTableResponse> done) {
    +        ByteString tenantId = request.getTenantId();
    +        ByteString schemaName = request.getSchemaName();
    +        ByteString tableName = request.getTableName();
    +        byte[] tableKey = SchemaUtil.getTableKey(tenantId.toByteArray(), schemaName.toByteArray()
, tableName.toByteArray());
    +        ImmutableBytesPtr key = new ImmutableBytesPtr(tableKey);
    +        Cache<ImmutableBytesPtr, PTable> metaDataCache =
    +                GlobalCache.getInstance(this.env).getMetaDataCache();
    +        PTable table = metaDataCache.getIfPresent(key);
    +        // Add +1 to the ts
    +        long ts = table.getTimeStamp() + 1;
    +        // Here we could add an empty put
    +        HRegion region = env.getRegion();
    +        List<Mutation> mutations = new ArrayList<Mutation>();
    +        Put p = new Put(tableKey);
    +        p.add(TABLE_FAMILY_BYTES, QueryConstants.EMPTY_COLUMN_BYTES, ts, ByteUtil.EMPTY_BYTE_ARRAY);
    +        mutations.add(p);
    +        try {
    +            region.mutateRowsWithLocks(mutations, Collections.<byte[]> emptySet());
    +        } catch (Throwable t) {
    +            // I think we could still invalidate it
    +            logger.error("clearCacheForTable failed to update the latest ts ", t);
    +            ProtobufUtil.setControllerException(controller, ServerUtil.createIOException(
    +                    SchemaUtil.getTableName(schemaName.toString(), tableName.toString()),
t));
    +        }
    +        // Should this invalidate happen in a lock? Then we need to add this every where
in the code
    +        metaDataCache.invalidate(key);
    --- End diff --
    
    Added a TODO. And instead of getting the PTable from the metaData myself am issuing a
doGetTable by passing the clientTS (in the protobuf) also and using  PTable  found  to invalidate
the cache.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message