Github user ramkrish86 commented on a diff in the pull request:

    https://github.com/apache/phoenix/pull/8#discussion_r16975421
  
    --- Diff: 
phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
 ---
    @@ -664,14 +698,161 @@ private PTable getTable(RegionScanner scanner, long 
clientTimeStamp, long tableT
               } else {
                   addColumnToTable(results, colName, famName, colKeyValues, 
columns, saltBucketNum != null);
               }
    +        }        
    +        byte[] tenIdBytes = QueryConstants.EMPTY_BYTE_ARRAY;
    +        if (tenantId != null) {
    +            tenIdBytes = tenantId.getBytes();
             }
    -
    +        byte[] schNameInBytes = QueryConstants.EMPTY_BYTE_ARRAY;
    +        if (schemaName != null) {
    +            schNameInBytes = Bytes.toBytes(schemaName.getString());
    +        }
    +        PTableStats stats = updateStats(SchemaUtil.getTableKey(tenIdBytes, 
schNameInBytes, tableNameBytes));
             return PTableImpl.makePTable(tenantId, schemaName, tableName, 
tableType, indexState, timeStamp, 
                 tableSeqNum, pkName, saltBucketNum, columns, tableType == 
INDEX ? dataTableName : null, 
                 indexes, isImmutableRows, physicalTables, defaultFamilyName, 
viewStatement, disableWAL, 
    -            multiTenant, viewType, viewIndexId, indexType);
    +            multiTenant, viewType, viewIndexId, indexType, stats);
         }
     
    +    private PTableStats updateStats(final byte[] tableNameBytes) {
    +        lock.readLock().lock();
    +        try {
    +            PTableStats stats = 
tableStatsMap.get(Bytes.toString(tableNameBytes));
    +            return stats;
    +        } finally {
    +            lock.readLock().unlock();
    +        }
    +    }
    +    
    +    private void updateStatsInternal(byte[] tableNameBytes, 
RegionCoprocessorEnvironment env)
    --- End diff --
    
    So this put that we make should have a timestamp (the current ts) added 
with it or leave it to the server to add it.
    
        // Query for the latest table first, since it's not cached
                table = buildTable(key, cacheKey, region, 
HConstants.LATEST_TIMESTAMP);
                if (table != null && table.getTimeStamp() < clientTimeStamp) {
                    return table;
                }
                // Otherwise, query for an older version of the table - it 
won't be cached
                return buildTable(key, cacheKey, region, clientTimeStamp);
    
    Suppose we add a cell (empty cell) so that we can udpdate the cache, still 
the above code will not allow to do that because before the first 'if' we try 
to use HConstants.LATEST_TIMESTAMP and inside buildTable() we were were 
updating the metaDataCache for the table with the timestamp of the cell that we 
created. (fine till here) but the if conditon would fail because 
table.getTimeStamp = the timestamp of the emtpy kv and the clienttimestamp = 
130 (for eg). So it goes into the second build table. There the passed 
timeSTamp = 130. So we create a PTable instance but with its timestamp as 130 
and we don't udpate the metadatacache. As this table (with ts = 130) is 
returned out 
    
                    if (table.getTimeStamp() != tableTimeStamp) {
                    builder.setTable(PTableImpl.toProto(table));
                }
    before building the PTable from the protos we check for the existing time 
stamp and the table's timestamp both of the matches and we end up in no created 
the table from the proto.  This internally means that for the FromCompiler the 
table ref is not updated with the latest. 



---
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 [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to