ivandasch commented on a change in pull request #8118: URL: https://github.com/apache/ignite/pull/8118#discussion_r470438811
########## File path: modules/platforms/cpp/thin-client/src/impl/transactions/transactions_impl.cpp ########## @@ -0,0 +1,252 @@ +/* + * 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 "impl/message.h" +#include "impl/transactions/transactions_impl.h" +#include "impl/response_status.h" + +using namespace ignite::common::concurrent; +using namespace ignite::impl::thin; + +namespace ignite +{ + namespace impl + { + namespace thin + { + namespace transactions + { + TransactionImpl::TL_TXID TransactionImpl::threadTx; + + TransactionsImpl::TransactionsImpl(const SP_DataRouter& router) : + router(router) + { + } + + std::map<int32_t, SP_TransactionImpl> TransactionImpl::txToId; + + ReadWriteLock TransactionImpl::txToIdRWLock; + + template<typename ReqT, typename RspT> + void TransactionsImpl::SyncMessage(const ReqT& req, RspT& rsp) + { + router.Get()->SyncMessage(req, rsp); + + if (rsp.GetStatus() != ResponseStatus::SUCCESS) + throw IgniteError(IgniteError::IGNITE_ERR_TX, rsp.GetError().c_str()); + } + + SharedPointer<TransactionImpl> TransactionsImpl::TxStart( + TransactionConcurrency::Type concurrency, + TransactionIsolation::Type isolation, + int64_t timeout, + int32_t txSize, + const char* label) + { + SP_TransactionImpl tx = TransactionImpl::Create(*this, concurrency, isolation, timeout, txSize, label); + + return tx; + } + + SP_TransactionImpl TransactionImpl::Create( + TransactionsImpl& txs, + TransactionConcurrency::Type concurrency, + TransactionIsolation::Type isolation, + int64_t timeout, + int32_t txSize, + const char* label) + { + int32_t txId = threadTx.Get(); + + SP_TransactionImpl tx; + + if (txId != 0) + { + std::map<int32_t, SP_TransactionImpl>::iterator it; + + { + RwSharedLockGuard lock(txToIdRWLock); + + it = txToId.find(txId); + } + + if (it != txToId.end()) Review comment: Why this is out of lock? I suppose this is not thread-safe ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
