Retrieves the last transaction id of the primary from zookeeper.

@param address
the address of the cluster
@param sync
whether or not to perform a sync before read
@throws IOException
@throws KeeperException
@throws InterruptedException
968864
public ZookeeperTxId getPrimaryLastTxId(String address, boolean sync)
      throws IOException,
      KeeperException, InterruptedException, ClassNotFoundException {
    Stat stat = new Stat();
    String node = getLastTxIdNode(address);
    byte[] data = getNodeData(node, stat, false, sync);
    if (data == null) {
      return null;
    }
    return ZookeeperTxId.getFromBytes(data);
  }
735725
void writeTransactionIdFile(StorageDirectory sd, long txid) throws IOException {
    if (txid < -1) {
      // -1 is valid when formatting
      throw new IOException("Bad txid: " + txid);
    }
    File txIdFile = getStorageFile(sd, NameNodeFile.SEEN_TXID);
    OutputStream fos = new AtomicFileOutputStream(txIdFile);
    try {
      fos.write(String.valueOf(txid).getBytes());
      fos.write('\n');
      fos.close();
      fos = null;
    } finally {
      IOUtils.cleanup(LOG, fos);
    }
  }
129376
public static boolean removeRejoinNodeIndicatorForHost(ZooKeeper zk, int hostId)
    {
        try {
            Stat stat = new Stat();
            final int rejoiningHost = ByteBuffer.wrap(zk.getData(rejoin_node_blocker, false, stat)).getInt();
            if (hostId == rejoiningHost) {
                zk.delete(rejoin_node_blocker, stat.getVersion());
                return true;
            }
        } catch (KeeperException e) {
            if (e.code() == KeeperException.Code.NONODE ||
                e.code() == KeeperException.Code.BADVERSION) {
                // Okay if the rejoin blocker for the given hostId is already gone.
                return true;
            }
        } catch (InterruptedException e) {
            return false;
        }
        return false;
    }
1200089
protected void updateLockHolder(String clientId, long lockDurationMs) {
        this.clientId = clientId;
        this.timestampExpiry = System.currentTimeMillis() + lockDurationMs;
    }
1167173
private SynchronizationAdapter createSynchronizationAdapter(Transaction transaction) {
      SynchronizationAdapter adapter = new SynchronizationAdapter(transaction, RemoteXid.create(uuid));
      try {
         transaction.registerSynchronization(adapter);
      } catch (RollbackException | SystemException e) {
         throw new CacheException(e);
      }
      if (trace) {
         log.tracef("Registered synchronization for transaction %s. Sync=%s", transaction, adapter);
      }
      return adapter;
   }
224701
public String getPrimaryAvatarAddress(String address, Stat stat, boolean retry)
      throws IOException, KeeperException, InterruptedException {
    return getPrimaryAvatarAddress(address, stat, retry, false);
  }
1257291
public static void updateCatalogToZK(ZooKeeper zk,
                                        int version,
                                        long genId,
                                        byte[] catalogBytes,
                                        byte[] catalogHash,
                                        byte[] deploymentBytes)
        throws KeeperException, InterruptedException
    {
        ByteBuffer versionAndBytes = makeCatalogAndDeploymentBytes(version, genId,
                catalogBytes, catalogHash, deploymentBytes);
        zk.setData(VoltZK.catalogbytes, versionAndBytes.array(), -1);
    }
706602
private void waitForLastTxIdNode(AvatarZooKeeperClient zk, Configuration conf)
      throws Exception {
    // Gather session id and transaction id data.
    String address = conf.get(NameNode.DFS_NAMENODE_RPC_ADDRESS_KEY);
    long maxWaitTime = this.getMaxWaitTimeForWaitTxid();
    long start = System.currentTimeMillis();
    while (true) {
      if (System.currentTimeMillis() - start > maxWaitTime) {
        throw new IOException("No valid last txid znode found");
      }
      try {
        long sessionId = zk.getPrimarySsId(address, false);
        ZookeeperTxId zkTxId = zk.getPrimaryLastTxId(address, false);
        if (sessionId != zkTxId.getSessionId()) {
          LOG.warn("Session Id in the ssid node : " + sessionId
              + " does not match the session Id in the txid node : "
              + zkTxId.getSessionId() + " retrying...");
          Thread.sleep(retrySleep);
          continue;
        }
      } catch (Throwable e) {
        LOG.warn("Caught exception : " + e + " retrying ...");
        Thread.sleep(retrySleep);
        continue;
      }
      break;
    }
  }
160270
synchronized ShortVoid journal(RequestInfo reqInfo, 
      long segmentTxId, long firstTxnId, 
      int numTxns, byte[] records) throws IOException {
    checkJournalStorageFormatted();
    checkWriteRequest(reqInfo);

    if (curSegment == null) {
      checkSync(false, "Can't write, no segment open");
    }
    
    if (curSegmentTxId != segmentTxId) {
      // Sanity check: it is possible that the writer will fail IPCs
      // on both the finalize() and then the start() of the next segment.
      // This could cause us to continue writing to an old segment
      // instead of rolling to a new one, which breaks one of the
      // invariants in the design. If it happens, abort the segment
      // and throw an exception.
      JournalOutOfSyncException e = new JournalOutOfSyncException(
          "Writer out of sync: it thinks it is writing segment " + segmentTxId
          + " but current segment is " + curSegmentTxId);
      abortCurSegment();
      throw e;
    }
      
    if (nextTxId != firstTxnId) {
      checkSync(false, "Can't write txid " + firstTxnId
          + " expecting nextTxId=" + nextTxId);
    }
    
    long lastTxnId = firstTxnId + numTxns - 1;
    if (LOG.isTraceEnabled()) {
      LOG.trace("Writing txid " + firstTxnId + "-" + lastTxnId);
    }

    // If the edit has already been marked as committed, we know
    // it has been fsynced on a quorum of other nodes, and we are
    // "catching up" with the rest. Hence we do not need to fsync.
    boolean isLagging = lastTxnId <= committedTxnId.get();
    boolean shouldFsync = !isLagging;
    
    curSegment.writeRaw(records, 0, records.length);
    curSegment.setReadyToFlush();
    long start = System.nanoTime();
    curSegment.flush(shouldFsync);
    long time = DFSUtil.getElapsedTimeMicroSeconds(start);
    currentSegmentWrittenBytes += records.length;
    
    metrics.addSync(time);
    
    if (time / 1000 > WARN_SYNC_MILLIS_THRESHOLD) {
      LOG.warn("Sync of transaction range " + firstTxnId + "-" + lastTxnId + 
               " took " + (time / 1000) + "ms");
    }

    if (isLagging) {
      // This batch of edits has already been committed on a quorum of other
      // nodes. So, we are in "catch up" mode. This gets its own metric.
      metrics.batchesWrittenWhileLagging.inc(1);
    }
    
    metrics.batchesWritten.inc(1);
    metrics.bytesWritten.inc(records.length);
    metrics.txnsWritten.inc(numTxns);
    
    highestWrittenTxId = lastTxnId;
    metrics.setLastWrittenTxId(highestWrittenTxId);
    metrics.setCurrentTxnsLag(getCurrentLagTxns());
    nextTxId = lastTxnId + 1;
    return ShortVoid.instance;
  }
658754
public static boolean isPartitionCleanupInProgress(ZooKeeper zk) throws KeeperException, InterruptedException
    {
        List<String> children = zk.getChildren(VoltZK.leaders_initiators, null);
        List<ZKUtil.ChildrenCallback> childrenCallbacks = Lists.newArrayList();
        for (String child : children) {
            ZKUtil.ChildrenCallback callback = new ZKUtil.ChildrenCallback();
            zk.getChildren(ZKUtil.joinZKPath(VoltZK.leaders_initiators, child), false, callback, null);
            childrenCallbacks.add(callback);
        }

        for (ZKUtil.ChildrenCallback callback : childrenCallbacks) {
            if (callback.get().isEmpty()) {
                return true;
            }
        }

        return false;
    }
767388
private Address getReplicaAddress(int partitionId, int replicaNumber, int backupCount) {
        IPartition partition = partitionService.getPartition(partitionId);
        Address replicaAddress = partition.getReplicaAddress(replicaNumber);
        if (replicaAddress == null) {
            replicaAddress = waitForReplicaAddress(replicaNumber, partition, backupCount);
        }
        return replicaAddress;
    }
1120981
private void synchronizePropertiesWithCRI() throws ResourceException {

        final boolean isTraceOn = TraceComponent.isAnyTracingEnabled();
        int previousTransactionIsolation = -1; // only used for debugging
        int previousHoldability = -1; //  - only used for debugging

        if (isTraceOn && tc.isEntryEnabled())
            Tr.entry(this, tc, "synchronizePropertiesWithCRI");

        try {
            isolationChanged = false;
            holdabilityChanged = false;

            if (kerberosConnection) {
                if (!AdapterUtil.matchGSSName(mc_gssName, cri.gssName)) {
                    if (isTraceOn && tc.isDebugEnabled()) 
                    {
                        Tr.debug(this, tc, "synching kerberos gssCredential on this mc and then clearing ps cache");
                    }

                    //  move the clearing of statement to before we issue the reuse.
                    // this will cover for cases where the reuse results in bad stuff. DB2 on Z seem to leak when this happens.
                    // reuse is supported with clean model only

                    // the cache gets created after the synchronizePropertiesWithCRI on newly created mc.
                    // thus, we should only call it if its not null here.  We don't want to have the check
                    // happen at the clearSTatementCache() since it puts a tr that cache is disabled (which si not the case)
                    if (statementCache != null) {
                        clearStatementCache();
                    }

                    // the reuse call won't go down to the DB til the next execution of the.  DB optimizaiton.
                    // if we were in a tran, a connection will have to match as we do compare subject and CRI
                    // the fact that the gssNames don't match, means we are not in a tra.
                    mcf.helper.reuseKerbrosConnection(sqlConn, cri.gssCredential, null);

                    //now save the cri props in the mc
                    mc_gssCredential = cri.gssCredential;
                    mc_gssName = cri.gssName;

                    // now that we issued the reuse, we need to purge the PS cache for this mc as
                    // reuse is supported with clean model only

                    handleCleanReuse();
                }
            }

            // Retrieve the default values for all Connection properties. 
            // Save the default values for when null is specified in the CRI. 
            previousTransactionIsolation = getTransactionIsolation();
            previousHoldability = currentHoldability;

            if (currentTransactionIsolation != cri.ivIsoLevel) {
                setTransactionIsolation(cri.ivIsoLevel);
            }

            if (cri.ivCatalog != null && !cri.ivCatalog.equals(defaultCatalog)) {
                setCatalog(cri.ivCatalog);
            }


            if (cri.ivReadOnly != null && defaultReadOnly != cri.ivReadOnly.booleanValue() && mcf.supportsIsReadOnly) {
                helper.setReadOnly(this, cri.ivReadOnly.booleanValue(), false); 
            }

            if (!AdapterUtil.match(cri.ivShardingKey, currentShardingKey)
             || !AdapterUtil.match(cri.ivSuperShardingKey, currentSuperShardingKey)) {
                setShardingKeys(cri.ivShardingKey, cri.ivSuperShardingKey);
            }

            if (cri.ivTypeMap != null && defaultTypeMap != cri.ivTypeMap && mcf.supportsGetTypeMap) {
                setTypeMap(cri.ivTypeMap);
            }
            
            if (mcf.supportsGetNetworkTimeout && cri.ivNetworkTimeout != currentNetworkTimeout) {
                final ExecutorService libertyThreadPool = mcf.connectorSvc.getLibertyThreadPool();
                // setNetworkTimeout is the only JDBC Connection property that may perform access checks
                if (System.getSecurityManager() == null) {
                    setNetworkTimeout(libertyThreadPool, cri.ivNetworkTimeout);
                } else {
                    try {
                        AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {
                            @Override
                            public Void run() throws Exception {
                                setNetworkTimeout(libertyThreadPool, cri.ivNetworkTimeout);
                                return null;
                            }
                        });
                    } catch (PrivilegedActionException e) {
                        if (e.getException() instanceof SQLException)
                            throw (SQLException) e.getException();
                        throw (RuntimeException) e.getException();
                    }
                }
            }

            if(mcf.supportsGetSchema && (cri.ivSchema != null || defaultSchema != null)){
                String targetSchema = cri.ivSchema == null ? defaultSchema : cri.ivSchema;
                if(!AdapterUtil.match(currentSchema, targetSchema))
                    setSchema(targetSchema);
            }

            //  - synchronize the holdability value to either cri value or default value
            // if the default value is not 0, which means the JDBC driver supports holdability.
            if (defaultHoldability != 0) {
                int targetHoldability = cri.ivHoldability == 0 ?
                                defaultHoldability : cri.ivHoldability;
                if (currentHoldability != targetHoldability) {
                    setHoldability(targetHoldability);
                }
            }

        } catch (SQLException sqlX) {
            FFDCFilter.processException(sqlX, getClass().getName() + ".synchronizePropertiesWithCRI", "850", this);
            ResourceException x = AdapterUtil.translateSQLException(sqlX, this, true, getClass()); 
            if (isTraceOn && tc.isEntryEnabled())
                Tr.exit(this, tc, "synchronizePropertiesWithCRI", sqlX);
            throw x;
        }

        if (isTraceOn && tc.isDebugEnabled()) 
        {
            Tr.debug(this, tc, "previous/current value:",
                                   "AutoCommit:    " + currentAutoCommit + "/" + currentAutoCommit,
                                   "Isolation:     " + AdapterUtil.getIsolationLevelString(previousTransactionIsolation) +
                                                   "/" + AdapterUtil.getIsolationLevelString(currentTransactionIsolation),
                                   "Catalog:       " + defaultCatalog + "/" + (cri.ivCatalog == null ? defaultCatalog : cri.ivCatalog),
                                   "Schema:        " + defaultSchema + "/" + (cri.ivSchema == null ? defaultSchema : cri.ivSchema),
                                   "ShardingKey:   " + initialShardingKey + "/" + cri.ivShardingKey,
                                   "SuperShardingK:" + initialSuperShardingKey + "/" + cri.ivSuperShardingKey,
                                   "NetworkTimeout:" + defaultNetworkTimeout + "/" + (cri.ivNetworkTimeout == 0 ? defaultNetworkTimeout : cri.ivNetworkTimeout),
                                   "IsReadOnly:    " + defaultReadOnly + "/" + (cri.ivReadOnly == null ? defaultReadOnly : cri.ivReadOnly), 
                                   "TypeMap:       " + defaultTypeMap + "/" + (cri.ivTypeMap == null ? defaultTypeMap : cri.ivTypeMap),
                                   "Holdability:   " + AdapterUtil.getCursorHoldabilityString(previousHoldability) +
                                                   "/" + AdapterUtil.getCursorHoldabilityString(currentHoldability));
        }

        if (isTraceOn && tc.isEntryEnabled())
            Tr.exit(this, tc, "synchronizePropertiesWithCRI");

    }
1054335
public void newTransactionHandler(PersistedTransaction tx, PersistedV2Key key) throws Exception {
        listenForUpdates(tx);
        tx.keyId = key.getId();
        tx.walletId = this.descriptor.getKey();
        tx.account = key.account;
        System.out.println("Incoming transaction captured in API service: " + tx.toString());
        transactionDAO.create(tx);
        WalletChange change = new WalletChange(tx.value, getBalance(), createKey(key.account).address, tx);
        WalletChangeMessage out = new WalletChangeMessage();
        out.setCommand(Command.BALANCE_CHANGE_RECEIVED);
        out.setKey(this.descriptor.key);
        out.setPayload(change);
        router.sendUpdate(this.descriptor.key, out);
    }
1156305
public SynchronizationRegistryUOWScope getCurrentTransactionalUOW(boolean checkMarkedRollback)
                    throws CSITransactionRolledbackException
    {
        UOWCoordinator coord = uowCurrent.getUOWCoord(); // 131880-6
        if (coord != null)
        {
            if (checkMarkedRollback && coord.getRollbackOnly()) // 131880-6 d173218.1
            {
                if (TraceComponent.isAnyTracingEnabled() && tc.isEventEnabled()) {
                    Tr.event(tc, "Attempting to do work on a tx " +
                                 "that has been marked rollback.");
                }
                throw new CSITransactionRolledbackException("Transaction rolled back");
            }
        } // if coord != null

        return (SynchronizationRegistryUOWScope) coord; // 131880-6

    }
88909
public void synchTransaction(SimpleFeatureStore featureStore) {
		// check if transaction is active, otherwise do nothing (auto-commit mode)
		if (TransactionSynchronizationManager.isActualTransactionActive()) {
			DataAccess<SimpleFeatureType, SimpleFeature> dataStore = featureStore.getDataStore();
			if (!transactions.containsKey(dataStore)) {
				Transaction transaction = null;
				if (dataStore instanceof JDBCDataStore) {
					JDBCDataStore jdbcDataStore = (JDBCDataStore) dataStore;
					transaction = jdbcDataStore.buildTransaction(DataSourceUtils
							.getConnection(jdbcDataStore.getDataSource()));
				} else {
					transaction = new DefaultTransaction();
				}
				transactions.put(dataStore, transaction);
			}
			featureStore.setTransaction(transactions.get(dataStore));
		}
	}
755337
public Result readCacheEntry(Object id, boolean calledFromRemove) {
        final String methodName = "readCacheEntry()";
        Result result = getFromResultPool();
        CacheEntry answer = null;
        if (this.invalidationBuffer.contains(id)) {
            return result;
        }
        HashtableEntry htEntry = null;
        boolean checkExpired = true;
        if (cache.isEnableListener() && cache.getEventSource().getInvalidationListenerCount() > 0 && this.cod.ignoreValueInInvalidationEvent == false) {
            checkExpired = false;
        }
        Object obj = null;
        try {
            rwLock.readLock().lock();
            //if (this.testException) {
            //    throw new FileManagerException("*** Generate filemanager exception");
            //}
            htEntry = object_cache.getHashTableEntry(id, checkExpired); // retrieve from HTOD
        } catch (FileManagerException ex) {
            this.diskCacheException = ex;
            result.diskException = ex;
            result.returnCode = DISK_EXCEPTION;
        } catch (HashtableOnDiskException ex) {
            this.diskCacheException = ex;
            result.diskException = ex;
            result.returnCode = DISK_EXCEPTION;
        } catch (IOException ex) {
            this.diskCacheException = ex;
            result.diskException = ex;
            result.returnCode = DISK_EXCEPTION;
        } catch (Exception ex) {
            result.returnCode = OTHER_EXCEPTION;
            result.diskException = ex;
        } finally {
            rwLock.readLock().unlock();
            if (result.returnCode != NO_EXCEPTION) {
                if (tc.isDebugEnabled())
                    Tr.debug(tc, methodName, "cacheName=" + this.cacheName + "\n Exception: " + ExceptionUtility.getStackTrace(result.diskException));
            }
            if (result.returnCode == DISK_EXCEPTION || result.returnCode == OTHER_EXCEPTION) {
                com.ibm.ws.ffdc.FFDCFilter.processException(result.diskException, "com.ibm.ws.cache.HTODDynacache.readCacheEntry", "916", this);
                return result;
            }
        }

        boolean expired = false;
        boolean alias = false;
        int dataSize = 0;
        Object origId = id;
        if (htEntry != null) {
            if (htEntry.isAliasId()) {
                alias = true;
                obj = htEntry.getValue();
                origId = obj;
                if (tc.isDebugEnabled())
                    Tr.debug(tc, methodName, "cacheName=" + this.cacheName + " found alias=" + id + " cacheId=" + origId);
                returnToHashtableEntryPool(htEntry);
                try {
                    rwLock.readLock().lock();
                    if (this.invalidationBuffer.contains(origId)) {
                        return result;
                    }
                    htEntry = object_cache.getHashTableEntry(origId, checkExpired); // retrieve from HTOD
                } catch (FileManagerException ex) {
                    this.diskCacheException = ex;
                    result.diskException = ex;
                    result.returnCode = DISK_EXCEPTION;
                } catch (HashtableOnDiskException ex) {
                    this.diskCacheException = ex;
                    result.diskException = ex;
                    result.returnCode = DISK_EXCEPTION;
                } catch (IOException ex) {
                    this.diskCacheException = ex;
                    result.diskException = ex;
                    result.returnCode = DISK_EXCEPTION;
                } catch (Exception ex) {
                    result.returnCode = OTHER_EXCEPTION;
                    result.diskException = ex;
                } finally {
                    rwLock.readLock().unlock();
                    if (result.returnCode != NO_EXCEPTION) {
                        if (tc.isDebugEnabled())
                            Tr.debug(tc, methodName, "cacheName=" + this.cacheName + "\n Exception: " + ExceptionUtility.getStackTrace(result.diskException));
                    }
                    if (result.returnCode == DISK_EXCEPTION || result.returnCode == OTHER_EXCEPTION) {
                        com.ibm.ws.ffdc.FFDCFilter.processException(result.diskException, "com.ibm.ws.cache.HTODDynacache.readCacheEntry", "916", this);
                        return result;
                    }
                }
            }
            if (htEntry != null) {
                if (htEntry.isExpired()) {
                    expired = true;
                    if (checkExpired) {
                        if (cache.isEnableListener() && cache.getEventSource().getInvalidationListenerCount() > 0) {
                            // In here - ignoreValueInInvalidationEvent = true
                            InvalidationEvent ie = new InvalidationEvent(origId, null, InvalidationEvent.DISK_TIMEOUT, InvalidationEvent.LOCAL, this.cache.getCacheName());
                            if (!this.invalidationBuffer.contains(origId)) {
                                this.cache.getEventSource().fireEvent(ie);
                            }
                        }
                        this.invalidationBuffer.add(origId, HTODInvalidationBuffer.EXPLICIT_BUFFER, CachePerf.TIMEOUT, CachePerf.LOCAL, !Cache.FROM_DEPID_TEMPLATE_INVALIDATION,
                                                    !HTODInvalidationBuffer.FIRE_EVENT, !HTODInvalidationBuffer.ALIAS_ID);
                        if (alias) {
                            this.invalidationBuffer.add(id, HTODInvalidationBuffer.EXPLICIT_BUFFER, CachePerf.TIMEOUT, CachePerf.LOCAL, !Cache.FROM_DEPID_TEMPLATE_INVALIDATION,
                                                        !HTODInvalidationBuffer.FIRE_EVENT, HTODInvalidationBuffer.ALIAS_ID);
                        }
                        if (this.cod.diskCachePerformanceLevel != CacheConfig.HIGH && !calledFromRemove) {
                            this.cache.internalInvalidateByDepId(origId, CachePerf.TIMEOUT, CachePerf.LOCAL, Cache.FIRE_INVALIDATION_LISTENER);
                        }
                        returnToHashtableEntryPool(htEntry);
                        return result;
                    }
                }
                // Retrieve CE and put data back in CE
                obj = htEntry.getValue();
                dataSize = htEntry.size();
                if (obj != null) {
                    try {
                        answer = (CacheEntry) SerializationUtility.deserialize((byte[]) obj, cacheName);
                        answer.setValidatorExpirationTime(htEntry.validatorExpirationTime());
                        byte[] serializedCacheValue = htEntry.getSerializedCacheValue();
                        if (serializedCacheValue != null) {
                            answer.serializedValue = serializedCacheValue;
                        }
                    } catch (Exception ex) {
                        result.returnCode = SERIALIZATION_EXCEPTION;
                        result.diskException = ex;
                        com.ibm.ws.ffdc.FFDCFilter.processException(result.diskException, "com.ibm.ws.cache.HTODDynacache.readCacheEntry", "953", this);
                        if (tc.isDebugEnabled())
                            Tr.debug(tc, methodName, "cacheName=" + this.cacheName + "\n Exception: " + ExceptionUtility.getStackTrace(result.diskException));
                    } finally {
                        returnToHashtableEntryPool(htEntry);
                    }
                }
            }
        }
        if (answer != null) {
            if (expired) {
                if (this.cache.isEnableListener() && cache.getEventSource().getInvalidationListenerCount() > 0) {
                    // In here - ignoreValueInInvalidationEvent = false
                    InvalidationEvent ie = new InvalidationEvent(answer.id, answer.serializedValue, InvalidationEvent.DISK_TIMEOUT, InvalidationEvent.LOCAL, this.cache.getCacheName());
                    if (!this.invalidationBuffer.contains(answer.id)) {
                        this.cache.getEventSource().fireEvent(ie);
                    }
                }
                this.invalidationBuffer.add(answer.id, HTODInvalidationBuffer.EXPLICIT_BUFFER, CachePerf.TIMEOUT, CachePerf.LOCAL, !Cache.FROM_DEPID_TEMPLATE_INVALIDATION,
                                            !HTODInvalidationBuffer.FIRE_EVENT, !HTODInvalidationBuffer.ALIAS_ID);
                for (int i = 0; i < answer.aliasList.length; i++) {
                    this.invalidationBuffer.add(answer.aliasList[i], HTODInvalidationBuffer.EXPLICIT_BUFFER, CachePerf.TIMEOUT, CachePerf.LOCAL,
                                                !Cache.FROM_DEPID_TEMPLATE_INVALIDATION, !HTODInvalidationBuffer.FIRE_EVENT, HTODInvalidationBuffer.ALIAS_ID);;
                }
                if (this.cod.diskCachePerformanceLevel != CacheConfig.HIGH && !calledFromRemove) {
                    //if (tc.isDebugEnabled()) Tr.debug(tc, methodName, "cacheName=" + this.cacheName + " id=" + answer.id + " check id as dep id");
                    this.cache.internalInvalidateByDepId(answer.id, CachePerf.TIMEOUT, CachePerf.LOCAL, Cache.FIRE_INVALIDATION_LISTENER);
                }
                answer = null;
            } else {
                if (!calledFromRemove && answer.serializedValue != null) {
                    this.cache.getCacheStatisticsListener().readEntryFromDisk(answer.id, dataSize);
                }
            }
        }
        result.data = answer;
        if (tc.isDebugEnabled())
            Tr.debug(tc, methodName, "cacheName=" + this.cacheName + " id=" + id + " cacheSizeInBytes=" + this.cod.currentCacheSizeInBytes);
        return result;
    }
877772
@Override
    public boolean addSync() throws ResourceException {

        if (tc.isEntryEnabled()) {
            Tr.entry(this, tc, "addSync");
        }

        UOWCoordinator uowCoord = mcWrapper.getUOWCoordinator();

        if (uowCoord == null) {
            IllegalStateException e = new IllegalStateException("addSync: illegal state exception. uowCoord is null");
            Tr.error(tc, "ILLEGAL_STATE_EXCEPTION_J2CA0079", "addSync", e);
            if (tc.isEntryEnabled())
                Tr.exit(this, tc, "addSync", e);
            throw e;
        }

        try {
            // added a second synchronization
            //
            // RRS Transactions don't follow the XA model, and therefore don't receive callbacks for
            // end, prepare, and commit/rollback.  Defect  added State Management for RRS
            // controlled transactions, and because the state on the adapter is, for XA transactions,
            // reset during the commit callback, we need to reset the adapter state as close as
            // possible after the commit time.  Therefore, we need to register as a priority sync
            // for the purpose of resetting the adapter state.  We need to also register as a normal
            // sync, however, because we have additional afterCompletion code that returns the
            // managed connection to the free pool.  This code must be executed AFTER DB2 gets its
            // afterCompletion callback.  DB2 is also registered as a priority sync, and since we
            // can't guarantee the order of the afterCompletion callbacks if two syncs are registered
            // as priority, we need to register as a regular sync to execute this part of the code.
            EmbeddableWebSphereTransactionManager tranMgr = mcWrapper.pm.connectorSvc.transactionManager;
            tranMgr.registerSynchronization(uowCoord, this); 
            final ManagedConnection mc = mcWrapper.getManagedConnection();

            // Registering a synchronization object with priority SYNC_TIER_RRS (3) allows the
            // synchronization to be called last.
            if (mc instanceof WSManagedConnection)
            {
                tranMgr.registerSynchronization( 
                uowCoord,
                                                new Synchronization()
                                                {
                                                    @Override
                                                    public void beforeCompletion() 
                                                    {
                                                    } 

                                                    @Override
                                                    public void afterCompletion(int status) 
                                                    {
                                                        ((WSManagedConnection) mc).afterCompletionRRS();
                                                    }
                                                },
                                                RegisteredSyncs.SYNC_TIER_RRS
               );
            }
        } catch (Exception e) {
            com.ibm.ws.ffdc.FFDCFilter.processException(
                                                        e,
                                                        "com.ibm.ejs.j2c.RRSGlobalTransactionWrapper.addSync",
                                                        "238",
                                                        this);
            Tr.error(tc, "REGISTER_WITH_SYNCHRONIZATION_EXCP_J2CA0026", "addSync", e, "ResourceException");
            ResourceException re = new ResourceException("addSync: caught Exception");
            re.initCause(e); 
            if (tc.isEntryEnabled())
                Tr.exit(this, tc, "addSync", e);
            throw re;
        }
        if (tc.isEntryEnabled()) {
            Tr.exit(this, tc, "addSync", true);
        }
        return true;
    }