1 /*
2  * Copyright (C) 2018 Codership Oy <info@codership.com>
3  *
4  * This file is part of wsrep-lib.
5  *
6  * Wsrep-lib is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * Wsrep-lib is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with wsrep-lib.  If not, see <https://www.gnu.org/licenses/>.
18  */
19 
20 /** @file storage_service.hpp
21  *
22  * Abstract interface which defines required access to DBMS storage
23  * service. The service is used for storing streaming replication
24  * write set fragments into stable storage. The interface is used
25  * from locally processing transaction context only. Corresponding
26  * operations for high priority processing can be found from
27  * wsrep::high_priority_service interface.
28  */
29 #ifndef WSREP_STORAGE_SERVICE_HPP
30 #define WSREP_STORAGE_SERVICE_HPP
31 
32 #include "transaction_id.hpp"
33 #include "id.hpp"
34 #include "buffer.hpp"
35 #include "xid.hpp"
36 
37 namespace wsrep
38 {
39     // Forward declarations
40     class ws_handle;
41     class ws_meta;
42     class transaction;
43 
44     /**
45      * Storage service abstract interface.
46      */
47     class storage_service
48     {
49     public:
~storage_service()50         virtual ~storage_service() { }
51         /**
52          * Start a new transaction for storage access.
53          *
54          * @param[out] ws_handle Write set handle for a new transaction
55          *
56          * @return Zero in case of success, non-zero on error.
57          */
58         virtual int start_transaction(const wsrep::ws_handle&) = 0;
59 
60         virtual void adopt_transaction(const wsrep::transaction&) = 0;
61         /**
62          * Append fragment into stable storage.
63          */
64         virtual int append_fragment(const wsrep::id& server_id,
65                                     wsrep::transaction_id client_id,
66                                     int flags,
67                                     const wsrep::const_buffer& data,
68                                     const wsrep::xid& xid) = 0;
69 
70         /**
71          * Update fragment meta data after certification process.
72          */
73         virtual int update_fragment_meta(const wsrep::ws_meta&) = 0;
74 
75         /**
76          * Remove fragments from storage. The storage service must have
77          * adopted a transaction prior this call.
78          */
79         virtual int remove_fragments() = 0;
80 
81         /**
82          * Commit the transaction.
83          */
84         virtual int commit(const wsrep::ws_handle&, const wsrep::ws_meta&) = 0;
85 
86         /**
87          * Roll back the transaction.
88          */
89         virtual int rollback(const wsrep::ws_handle&,
90                              const wsrep::ws_meta&) = 0;
91 
92 
93         virtual void store_globals() = 0;
94         virtual void reset_globals() = 0;
95     };
96 }
97 
98 #endif // WSREP_STORAGE_SERVICE_HPP
99