Package org.lealone.hbase.transaction

Examples of org.lealone.hbase.transaction.TransactionStatusCache


        }
    }

    private static TransactionStatusCache newCache(String hostAndPort) {
        synchronized (TransactionStatusTable.class) {
            TransactionStatusCache cache = hostAndPortMap.get(hostAndPort);
            if (cache == null) {
                cache = new TransactionStatusCache();
                hostAndPortMap.put(hostAndPort, cache);
            }

            return cache;
        }
View Full Code Here


     * @param oldTid 所要检查的行存入数据库的旧事务id
     * @param currentTransaction 当前事务
     * @return true 有效
     */
    public boolean isValid(String hostAndPort, long oldTid, Transaction currentTransaction) {
        TransactionStatusCache cache = hostAndPortMap.get(hostAndPort);
        if (cache == null) {
            cache = newCache(hostAndPort);
        }
        long commitTimestamp = cache.get(oldTid);
        //1.上一次已经查过了,已确认过是条无效的记录
        if (commitTimestamp == -2)
            return false;
        //2. 是有效的事务记录,再进一步判断是否小于等于当前事务的开始时间戳
        if (commitTimestamp != -1)
            return commitTimestamp <= currentTransaction.getTransactionId();

        String oldTransactionName = Transaction.getTransactionName(hostAndPort, oldTid);
        Get get = new Get(Bytes.toBytes(oldTransactionName));
        try {
            Result r = table.get(get);
            if (r != null && !r.isEmpty()) {
                boolean isFullSuccessful = true;
                commitTimestamp = Bytes.toLong(r.getValue(MetaDataAdmin.DEFAULT_COLUMN_FAMILY, COMMIT_TIMESTAMP));
                String[] allLocalTransactionNames = Bytes.toString(
                        r.getValue(MetaDataAdmin.DEFAULT_COLUMN_FAMILY, ALL_LOCAL_TRANSACTION_NAMES)).split(",");
                for (String localTransactionName : allLocalTransactionNames) {
                    if (!oldTransactionName.equals(localTransactionName)) {
                        get = new Get(Bytes.toBytes(localTransactionName));
                        if (!table.exists(get)) {
                            isFullSuccessful = false;
                            break;
                        }
                    }
                }

                if (isFullSuccessful)
                    cache.set(oldTid, commitTimestamp);

                if (commitTimestamp <= currentTransaction.getTransactionId()) {
                    if (!isFullSuccessful)
                        currentTransaction.addHalfSuccessfulTransaction(oldTid);

                    return true;
                } else {
                    return false;
                }
            } else {
                cache.set(oldTid, -2);
                return false;
            }
        } catch (IOException e) {
            throw DbException.convert(e);
        }
View Full Code Here

            throw DbException.convert(e);
        }
    }

    public boolean isFullSuccessful(String hostAndPort, long tid) {
        TransactionStatusCache cache = hostAndPortMap.get(hostAndPort);
        if (cache == null) {
            cache = newCache(hostAndPort);
        }
        if (cache.get(tid) > 0)
            return true;

        String transactionName = Transaction.getTransactionName(hostAndPort, tid);
        Get get = new Get(Bytes.toBytes(transactionName));
        try {
View Full Code Here

TOP

Related Classes of org.lealone.hbase.transaction.TransactionStatusCache

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.