MysqlCatalogue.hpp 8.89 KB
Newer Older
Tao Lin's avatar
Tao Lin committed
1
/*
2
 * @project        The CERN Tape Archive (CTA)
3
 * @copyright      Copyright(C) 2015-2021 CERN
4
5
6
7
 * @license        This program is free software: you can redistribute it and/or modify
 *                 it under the terms of the GNU General Public License as published by
 *                 the Free Software Foundation, either version 3 of the License, or
 *                 (at your option) any later version.
Tao Lin's avatar
Tao Lin committed
8
 *
9
10
11
12
 *                 This program is distributed in the hope that it will be useful,
 *                 but WITHOUT ANY WARRANTY; without even the implied warranty of
 *                 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *                 GNU General Public License for more details.
Tao Lin's avatar
Tao Lin committed
13
 *
14
15
 *                 You should have received a copy of the GNU General Public License
 *                 along with this program.  If not, see <http://www.gnu.org/licenses/>.
Tao Lin's avatar
Tao Lin committed
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
 */

#pragma once

#include "catalogue/RdbmsCatalogue.hpp"
#include "rdbms/Login.hpp"

namespace cta {
namespace catalogue {

class CatalogueFactory;

/**
 * A MySQL implementation of the CTA catalogue.
 */
class MysqlCatalogue: public RdbmsCatalogue {
public:

  /**
   * Constructor.
   *
   * @param log Object representing the API to the CTA logging system.
   * @param login Login object to connect MySQL server.
   * @param nbConns The maximum number of concurrent connections to the
   * underlying relational database for all operations accept listing archive
   * files which can be relatively long operations.
   * @param nbArchiveFileListingConns The maximum number of concurrent
   * connections to the underlying relational database for the sole purpose of
   * listing archive files.
   */
  MysqlCatalogue(
    log::Logger &log,
    const rdbms::Login &login,
    const uint64_t nbConns,
50
    const uint64_t nbArchiveFileListingConns);
Tao Lin's avatar
Tao Lin committed
51
52
53
54
55
56
57
58
59

  /**
   * Destructor.
   */
  ~MysqlCatalogue() override;

protected:

  /**
60
61
62
63
64
65
66
67
68
   * Creates a temporary table from the list of disk file IDs provided in the search criteria.
   *
   * @param conn The database connection.
   * @param tapeFileSearchCriteria Search criteria containing a list of disk file IDs (fxid).
   * @return Name of the temporary table
   */
  std::string createAndPopulateTempTableFxid(rdbms::Conn &conn, const TapeFileSearchCriteria &tapeFileSearchCriteria) const override;

  /**
Tao Lin's avatar
Tao Lin committed
69
70
71
72
73
74
75
76
77
78
79
80
81
   * Returns a unique archive ID that can be used by a new archive file within
   * the catalogue.
   *
   * This method must be implemented by the sub-classes of RdbmsCatalogue
   * because different database technologies propose different solutions to the
   * problem of generating ever increasing numeric identifiers.
   *
   * @param conn The database connection.
   * @return A unique archive ID that can be used by a new archive file within
   * the catalogue.
   */
  uint64_t getNextArchiveFileId(rdbms::Conn &conn) override;

82
83
84
85
86
87
88
89
90
91
92
93
94
  /**
   * Returns a unique logical library ID that can be used by a new logical
   * library within the catalogue.
   *
   * This method must be implemented by the sub-classes of RdbmsCatalogue
   * because different database technologies propose different solution to the
   * problem of generating ever increasing numeric identifiers.
   *
   * @param conn The database connection.
   * @return a unique logical library ID that can be used by a new logical
   * library storage class within the catalogue.
   */
  uint64_t getNextLogicalLibraryId(rdbms::Conn &conn) override;
95
96
97
98
99
100
101
102
103
104
105
106
107
108
  
  /**
   * Returns a unique virtual organization ID that can be used by a new Virtual Organization
   * within the catalogue.
   * 
   * This method must be implemented by the sub-classes of RdbmsCatalogue
   * because different database technologies propose different solution to the
   * problem of generating ever increasing numeric identifiers.
   * 
   * @param conn The database connection
   * @return a unique virtual organization ID that can be used by a new Virtual Organization
   * within the catalogue.
   */
  uint64_t getNextVirtualOrganizationId(rdbms::Conn &conn) override;
109

110
111
112
113
114
115
116
117
118
119
120
121
122
123
  /**
   * Returns a unique media type ID that can be used by a new media type within
   * the catalogue.
   *
   * This method must be implemented by the sub-classes of RdbmsCatalogue
   * because different database technologies propose different solution to the
   * problem of generating ever increasing numeric identifiers.
   *
   * @param conn The database connection.
   * @return a unique media type ID that can be used by a new media type
   * within the catalogue.
   */
  uint64_t getNextMediaTypeId(rdbms::Conn &conn) override;

Tao Lin's avatar
Tao Lin committed
124
125
126
127
128
129
130
131
132
  /**
   * Returns a unique storage class ID that can be used by a new storage class
   * within the catalogue.
   *
   * This method must be implemented by the sub-classes of RdbmsCatalogue
   * because different database technologies propose different solution to the
   * problem of generating ever increasing numeric identifiers.
   *
   * @param conn The database connection.
133
   * @return a unique storage class ID that can be used by a new storage class
Tao Lin's avatar
Tao Lin committed
134
135
136
137
   * within the catalogue.
   */
  uint64_t getNextStorageClassId(rdbms::Conn &conn) override;

138
139
140
141
142
143
144
145
146
147
148
149
150
  /**
   * Returns a unique tape pool ID that can be used by a new tape pool within
   * the catalogue.
   *
   * This method must be implemented by the sub-classes of RdbmsCatalogue
   * because different database technologies propose different solution to the
   * problem of generating ever increasing numeric identifiers.
   *
   * @param conn The database connection.
   * @return a unique tape pool ID that can be used by a new tape pool within
   * the catalogue.
   */
  uint64_t getNextTapePoolId(rdbms::Conn &conn) override;
Cedric Caffy's avatar
Cedric Caffy committed
151
152
153
154
155
156
157
158
159
160
161
162
163
164
  
  /**
   * Returns a unique file recycle log ID that can be used by a new entry of file recycle log within
   * the catalogue.
   *
   * This method must be implemented by the sub-classes of RdbmsCatalogue
   * because different database technologies propose different solution to the
   * problem of generating ever increasing numeric identifiers.
   *
   * @param conn The database connection.
   * @return a unique file recycle log ID that can be used by a new entry of file recycle log within
   * the catalogue.
   */
  uint64_t getNextFileRecyleLogId(rdbms::Conn & conn) override;
165

Tao Lin's avatar
Tao Lin committed
166
167
168
169
170
171
172
  /**
   * Notifies the catalogue that the specified files have been written to tape.
   *
   * @param events The tape file written events.
   */
  void filesWrittenToTape(const std::set<TapeItemWrittenPointer> &events) override;

173
  /**
174
   * !!!!!!!!!!!!!!!!!!! THIS METHOD SHOULD NOT BE USED !!!!!!!!!!!!!!!!!!!!!!!
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
   * Deletes the specified archive file and its associated tape copies from the
   * catalogue.
   *
   * Please note that the name of the disk instance is specified in order to
   * prevent a disk instance deleting an archive file that belongs to another
   * disk instance.
   *
   * Please note that this method is idempotent.  If the file to be deleted does
   * not exist in the CTA catalogue then this method returns without error.
   *
   * @param instanceName The name of the instance from where the deletion request
   * originated
   * @param archiveFileId The unique identifier of the archive file.
   * @param lc The log context.
   * @return The metadata of the deleted archive file including the metadata of
   * the associated and also deleted tape copies.
   */
192
  void DO_NOT_USE_deleteArchiveFile_DO_NOT_USE(const std::string &instanceName, const uint64_t archiveFileId,
193
194
    log::LogContext &lc) override;

195
  /**
196
   * Copy the archiveFile and the associated tape files from the ARCHIVE_FILE and TAPE_FILE tables to the FILE_RECYCLE_LOG table
197
198
   * and deletes the ARCHIVE_FILE and TAPE_FILE entries.
   * @param conn the database connection
199
   * @param request the request that contains the necessary informations to identify the archiveFile to copy to the FILE_RECYCLE_LOG table
200
201
   * @param lc the log context
   */
202
  void copyArchiveFileToFileRecyleLogAndDelete(rdbms::Conn & conn,const common::dataStructures::DeleteArchiveRequest &request, log::LogContext & lc) override;
203
204
205
206
207
208
209
210
  
  /**
   * Delete the TapeFiles and the ArchiveFile from the recycle-bin in one transaction
   * @param conn the database connection
   * @param archiveFileId the archiveFileId of the file to delete from the recycle-bin
   */
  void deleteTapeFilesAndArchiveFileFromRecycleBin(rdbms::Conn & conn, const uint64_t archiveFileId, log::LogContext & lc) override;
  
Tao Lin's avatar
Tao Lin committed
211
212
213
214
215
216
217
218
private:

  /**
   * Notifies the catalogue that a file has been written to tape.
   *
   * @param conn The database connection.
   * @param event The tape file written event.
   */
219
  void fileWrittenToTape(rdbms::Conn &conn, const TapeFileWritten &event);
Tao Lin's avatar
Tao Lin committed
220
221

  /**
222
   * Selects the specified tape for update and returns its last FSeq.
Tao Lin's avatar
Tao Lin committed
223
224
225
   *
   * @param conn The database connection.
   * @param vid The volume identifier of the tape.
226
   * @return The last FSeq of the tape.
Tao Lin's avatar
Tao Lin committed
227
   */
228
  uint64_t selectTapeForUpdateAndGetLastFSeq(rdbms::Conn &conn, const std::string &vid);
Tao Lin's avatar
Tao Lin committed
229
230
231
232
}; // class MysqlCatalogue

} // namespace catalogue
} // namespace cta