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

    https://github.com/apache/phoenix/pull/130#discussion_r45427160
  
    --- Diff: 
phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java ---
    @@ -415,24 +425,47 @@ private long getClientTimeStamp() {
             long clientTimeStamp = scn == null ? HConstants.LATEST_TIMESTAMP : 
scn;
             return clientTimeStamp;
         }
    -
    +    
    +    private long getCurrentScn() {
    +           Long scn = connection.getSCN();
    +        long currentScn = scn == null ? HConstants.LATEST_TIMESTAMP : scn;
    +        return currentScn;
    +    }
    +    
         private MetaDataMutationResult updateCache(PName tenantId, String 
schemaName, String tableName,
    -            boolean alwaysHitServer) throws SQLException { // TODO: pass 
byte[] herez
    -        long clientTimeStamp = getClientTimeStamp();
    +            boolean alwaysHitServer, Long resolvedTimestamp) throws 
SQLException { // TODO: pass byte[] herez
             boolean systemTable = SYSTEM_CATALOG_SCHEMA.equals(schemaName);
             // System tables must always have a null tenantId
             tenantId = systemTable ? null : tenantId;
             PTable table = null;
    +        PTableRef tableRef = null;
             String fullTableName = SchemaUtil.getTableName(schemaName, 
tableName);
             long tableTimestamp = HConstants.LATEST_TIMESTAMP;
    +        long tableResolvedTimestamp = HConstants.LATEST_TIMESTAMP;
             try {
    -            table = connection.getTable(new PTableKey(tenantId, 
fullTableName));
    +            tableRef = connection.getTableRef(new PTableKey(tenantId, 
fullTableName));
    +            table = tableRef.getTable();
                 tableTimestamp = table.getTimeStamp();
    +            tableResolvedTimestamp = tableRef.getResolvedTimeStamp();
             } catch (TableNotFoundException e) {
             }
    -        // Don't bother with server call: we can't possibly find a newer 
table
    -        if (table != null && !alwaysHitServer && (systemTable || 
tableTimestamp == clientTimeStamp - 1)) {
    -            return new 
MetaDataMutationResult(MutationCode.TABLE_ALREADY_EXISTS,QueryConstants.UNSET_TIMESTAMP,table);
    +        
    +        boolean defaultTransactional = 
connection.getQueryServices().getProps().getBoolean(
    +                                                                   
QueryServices.DEFAULT_TRANSACTIONAL_ATTRIB,
    +                                                                   
QueryServicesOptions.DEFAULT_TRANSACTIONAL);
    +        // start a txn if all table are transactional by default or if we 
found the table in the cache and it is transactional
    +        // TODO if system tables become transactional remove the check 
    +        boolean isTransactional = defaultTransactional || (table!=null && 
table.isTransactional());
    +        if (!systemTable && isTransactional && 
!connection.getMutationState().isTransactionStarted()) {
    +           connection.getMutationState().startTransaction();
    --- End diff --
    
    Question for my understanding - what is the purpose of starting a 
transaction when updating the metadatacache. Is there a code path which leads 
to updateCache and  the table involved isn't already part of a transaction?


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to