Skip to content

Commit 849985e

Browse files
committed
start hashing table content
1 parent dde444e commit 849985e

3 files changed

Lines changed: 27 additions & 10 deletions

File tree

DbService/data/create.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ GRANT UPDATE ON val.tables_tid_seq TO manager_role;
4040
CREATE TABLE val.calibrations
4141
(cid SERIAL,
4242
tid INTEGER NOT NULL,
43+
chash TEXT NOT NULL DEFAULT '',
4344
create_time TIMESTAMP WITH TIME ZONE NOT NULL,
4445
create_user TEXT NOT NULL,
4546
CONSTRAINT calibrations_pk PRIMARY KEY (cid),

DbService/src/DbTool.cc

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,13 @@ int mu2e::DbTool::printCalibration() {
170170
args["user"] = "";
171171
args["cid"] = "";
172172
args["ctime"] = "";
173+
args["hash"] = "";
173174
if ((rc = getArgs(args))) return rc;
174175
std::string name = args["name"];
175176
std::string user = args["user"];
176177
std::vector<int> cids = intList(args["cid"]);
177178
timeInterval tint = parseInterval(args["ctime"]);
179+
std::string chash = args["hash"];
178180

179181
// if this is a val table, just exit - there is no summary line
180182
if (name.substr(0, 3) == "Val") {
@@ -202,7 +204,9 @@ int mu2e::DbTool::printCalibration() {
202204
if (tid < 0 || cc.tid() == tid) {
203205
if (user.empty() || user == cc.create_user()) {
204206
if (tint.start == 0 || inTime(tint, cc.create_time())) {
205-
cids.push_back(cc.cid());
207+
if (chash.empty() || chash == cc.chash() ) {
208+
cids.push_back(cc.cid());
209+
}
206210
}
207211
}
208212
}
@@ -764,9 +768,9 @@ int mu2e::DbTool::printCIDLine(int cid, int indent) {
764768
auto name = tids.row(cr.tid()).name();
765769

766770
std::stringstream ss;
767-
ss << "CID " << std::setw(5 + 4 * std::max(indent, 0)) << cid << std::setw(20)
768-
<< name << std::setw(12) << cr.create_user() << std::setw(35)
769-
<< cr.create_time() << std::endl;
771+
ss << "CID " << std::setw(5 + 4 * std::max(indent, 0)) << cid << std::setw(22)
772+
<< name << std::setw(12) << cr.create_user()
773+
<< std::setw(35) << cr.create_time() << std::endl;
770774
_result.append(ss.str());
771775

772776
return 0;
@@ -1037,13 +1041,21 @@ int mu2e::DbTool::commitCalibrationList(DbTableCollection& coll, bool qai,
10371041

10381042
liveTable.setTid(tid);
10391043

1044+
if (ptr->hash().empty()) {
1045+
std::cout
1046+
<< "DbTool::commitCalibrationList found empty hash summary for table named "
1047+
<< liveTable.table().name() << std::endl;
1048+
return 1;
1049+
}
1050+
10401051
command = "SET ROLE val_role;";
10411052
rc = _sql.execute(command, result);
10421053
if (rc != 0) return rc;
10431054

10441055
command =
1045-
"INSERT INTO val.calibrations (tid,create_time,create_user) VALUES (" +
1046-
std::to_string(tid) + ",CURRENT_TIMESTAMP,SESSION_USER) RETURNING cid;";
1056+
"INSERT INTO val.calibrations (tid,chash,create_time,create_user) VALUES (" +
1057+
std::to_string(tid) + ",'" + ptr->hash() +
1058+
"',CURRENT_TIMESTAMP,SESSION_USER) RETURNING cid;";
10471059
rc = _sql.execute(command, result);
10481060
if (rc != 0) return rc;
10491061

@@ -2747,6 +2759,7 @@ int mu2e::DbTool::help() {
27472759
" [OPTIONS]\n"
27482760
" --name NAME : name of the table\n"
27492761
" --user USERNAME : only print tables committed by this user \n"
2762+
" --hash HASH : only print table with this content hash \n"
27502763
" --ctime TIME/TIME : only print contents created in this "
27512764
"interval \n"
27522765
" --cid INT or INT LIST : only print this cid \n"

DbTables/inc/ValCalibrations.hh

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,27 @@ class ValCalibrations : public DbTable {
1313
public:
1414
class Row {
1515
public:
16-
Row(int cid, int tid, std::string create_time, std::string create_user) :
17-
_cid(cid), _tid(tid), _create_time(create_time),
16+
Row(int cid, int tid, std::string chash, std::string create_time, std::string create_user) :
17+
_cid(cid), _tid(tid), _chash(chash), _create_time(create_time),
1818
_create_user(create_user) {}
1919
int tid() const { return _tid; }
2020
int cid() const { return _cid; }
21+
std::string const& chash() const { return _chash; }
2122
std::string const& create_time() const { return _create_time; }
2223
std::string const& create_user() const { return _create_user; }
2324

2425
private:
2526
int _cid;
2627
int _tid;
28+
std::string _chash;
2729
std::string _create_time;
2830
std::string _create_user;
2931
};
3032

3133
constexpr static const char* cxname = "ValCalibrations";
3234

3335
ValCalibrations() :
34-
DbTable(cxname, "val.calibrations", "cid,tid,create_time,create_user") {}
36+
DbTable(cxname, "val.calibrations", "cid,tid,chash,create_time,create_user") {}
3537

3638
const Row& rowAt(const std::size_t index) const { return _rows.at(index); }
3739
const Row& row(const int cid) const { return _rows.at(_index.at(cid)); }
@@ -44,14 +46,15 @@ class ValCalibrations : public DbTable {
4446

4547
void addRow(const std::vector<std::string>& columns) override {
4648
_rows.emplace_back(std::stoi(columns[0]), std::stoi(columns[1]), columns[2],
47-
columns[3]);
49+
columns[3],columns[4]);
4850
_index[_rows.back().cid()] = _rows.size() - 1;
4951
}
5052

5153
void rowToCsv(std::ostringstream& sstream, std::size_t irow) const override {
5254
Row const& r = _rows.at(irow);
5355
sstream << r.cid() << ",";
5456
sstream << r.tid() << ",";
57+
sstream << r.chash() << ",";
5558
sstream << r.create_time() << ",";
5659
sstream << r.create_user();
5760
}

0 commit comments

Comments
 (0)