1 /*
2  * ConflictSet.h
3  *
4  * This source file is part of the FoundationDB open source project
5  *
6  * Copyright 2013-2018 Apple Inc. and the FoundationDB project authors
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *     http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 #ifndef CONFLICTSET_H
22 #define CONFLICTSET_H
23 #pragma once
24 
25 #include "fdbclient/CommitTransaction.h"
26 
27 struct ConflictSet;
28 ConflictSet* newConflictSet();
29 void clearConflictSet( ConflictSet*, Version );
30 void destroyConflictSet(ConflictSet*);
31 
32 struct ConflictBatch {
33 	explicit ConflictBatch( ConflictSet* );
34 	~ConflictBatch();
35 
36 	enum TransactionCommitResult {
37 		TransactionConflict = 0,
38 		TransactionTooOld,
39 		TransactionCommitted,
40 	};
41 
42 	void addTransaction( const CommitTransactionRef& transaction );
43 	void detectConflicts(Version now, Version newOldestVersion, vector<int>& nonConflicting, vector<int>* tooOldTransactions = NULL);
44 	void GetTooOldTransactions(vector<int>& tooOldTransactions);
45 
46 private:
47 	ConflictSet* cs;
48 	Standalone< VectorRef< struct TransactionInfo* > > transactionInfo;
49 	vector<struct KeyInfo> points;
50 	int transactionCount;
51 	vector< pair<StringRef,StringRef> > combinedWriteConflictRanges;
52 	vector< struct ReadConflictRange > combinedReadConflictRanges;
53 	bool* transactionConflictStatus;
54 
55 	void checkIntraBatchConflicts();
56 	void combineWriteConflictRanges();
57 	void checkReadConflictRanges();
58 	void mergeWriteConflictRanges(Version now);
59 	void addConflictRanges(Version now, vector< pair<StringRef,StringRef> >::iterator begin, vector< pair<StringRef,StringRef> >::iterator end, class SkipList* part);
60 };
61 
62 #endif