#ifndef QPID_STORE_MSCLFS_TRANSACTIONLOG_H #define QPID_STORE_MSCLFS_TRANSACTIONLOG_H /* * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ #include #include #include #include #include #include #include "Log.h" namespace qpid { namespace store { namespace ms_clfs { class Transaction; class TPCTransaction; /** * @class TransactionLog * * Represents a CLFS-housed transaction log. */ class TransactionLog : public Log, public boost::enable_shared_from_this { // To know when it's ok to move the log tail the lowest valid Id must // always be known. Keep track of valid Ids here. These are transactions // which have not yet been Deleted in the log. They may be new, in progress, // prepared, committed, or aborted - but not deleted. // Entries corresponding to not-yet-finalized transactions (i.e., open or // prepared) also have a weak_ptr so the Transaction can be accessed. // This is primarily to check its state and get a list of prepared Xids. std::map > validIds; qpid::sys::Mutex idsLock; protected: // Transaction log needs to have a no-op first record written in the log // to ensure that no real transaction gets an ID 0; messages think trans // id 0 means "no transaction." virtual void initialize(); public: // Inherited and reimplemented from Log. Figure the minimum marshalling // buffer size needed for the records this class writes. virtual uint32_t marshallingBufferSize(); typedef boost::shared_ptr shared_ptr; // Get a new Transaction boost::shared_ptr begin(); // Get a new TPCTransaction boost::shared_ptr begin(const std::string& xid); void recordPrepare(uint64_t transId); void recordCommit(uint64_t transId); void recordAbort(uint64_t transId); void deleteTransaction(uint64_t transId); // Fill @arg preparedMap with Xid->TPCTransaction::shared_ptr for all // currently prepared transactions. void collectPreparedXids(std::map >& preparedMap); // Recover the transactions and their state from the log. // Every non-deleted transaction recovered from the log will be // represented in @arg transMap. The recovering messages can use this // information to tell if a transaction referred to in an enqueue/dequeue // operation should be recovered or dropped by examining transaction state. // // @param recoverer Recovery manager used to recreate broker objects from // entries recovered from the log. // @param transMap This method fills in the map of id -> shared_ptr of // recovered transactions. void recover(std::map >& transMap); }; }}} // namespace qpid::store::ms_clfs #endif /* QPID_STORE_MSCLFS_TRANSACTIONLOG_H */