From 10ee833002db08023d53ec5e843ccb0b402f7c51 Mon Sep 17 00:00:00 2001 From: happyZYM Date: Sat, 25 May 2024 00:32:21 +0000 Subject: [PATCH] fix fatal errors --- src/include/transaction_mainenance.hpp | 8 ++++++++ src/transaction_system.cpp | 4 ++-- test/hash_collision_test.cpp | 1 + 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/include/transaction_mainenance.hpp b/src/include/transaction_mainenance.hpp index 306a57c..fe6df48 100644 --- a/src/include/transaction_mainenance.hpp +++ b/src/include/transaction_mainenance.hpp @@ -165,6 +165,10 @@ class TransactionManager : public DataDriverBase { b_plus_tree_value_index_t data_id = data_storage->write(tmp); hash_t train_ID_hash = SplitMix64Hash(trainID); hash_t user_ID_hash = SplitMix64Hash(username); + LOG->debug("adding order trainID {} from {} to {} status {} leave {} arrive {} num {} price {} date {} user {}", + trainID, from_station_name, to_station_name, status, leave_time_stamp, arrive_time_stamp, num, + total_price, running_date_offset, username); + LOG->debug("user_ID_hash: {}", user_ID_hash); if (status == 0) { queue_index_t queue_index_for_query; queue_index_for_query.train_ID_hash = train_ID_hash; @@ -194,6 +198,8 @@ class TransactionManager : public DataDriverBase { order_history_index_t order_history_index; order_history_index.user_ID_hash = user_ID_hash; order_history_index.id = new_id; + LOG->debug("new_id: {}", new_id); + LOG->debug("data_id: {}", data_id); order_history_indexer->Put(order_history_index, data_id); } inline void FetchQueue(hash_t train_ID_hash, uint8_t running_date_offset, @@ -208,6 +214,8 @@ class TransactionManager : public DataDriverBase { res.resize(total_num); for (int i = 0; i < total_num; i++) { ++it; + if (it == queue_indexer->end_const()) break; + if (it.GetKey().train_ID_hash != train_ID_hash || it.GetKey().running_offset != running_date_offset) break; res[i].first = it.GetValue(); res[i].second = it.GetKey().id; } diff --git a/src/transaction_system.cpp b/src/transaction_system.cpp index d649572..2aa2921 100644 --- a/src/transaction_system.cpp +++ b/src/transaction_system.cpp @@ -163,7 +163,7 @@ std::string TicketSystemEngine::QueryTransfer(const std::string &command) { LOG->debug("date {}={}-{}, from {}, to {}, order by {}", date, RetrieveReadableDate(date).first, RetrieveReadableDate(date).second, from, to, order_by); // TODO - response_stream << "[" << command_id << "] QueryTransfer"; + response_stream << "[" << command_id << "] 0"; return response_stream.str(); } @@ -404,10 +404,10 @@ std::string TicketSystemEngine::RefundTicket(const std::string &command) { for (int j = cur_txn_data.from_stop_id; j < cur_txn_data.to_stop_id; j++) { seats_data.seat[j] -= cur_txn_data.num; } - seats_data_storage.Put({train_ID_hash, txn_data.running_date_offset}, seats_data); transaction_manager.RemoveOrderFromQueue(train_ID_hash, txn_data.running_date_offset, queue_idxs[i].second); } } + seats_data_storage.Put({train_ID_hash, txn_data.running_date_offset}, seats_data); response_stream << "[" << command_id << "] 0"; return response_stream.str(); } \ No newline at end of file diff --git a/test/hash_collision_test.cpp b/test/hash_collision_test.cpp index c246776..3c3bbd5 100644 --- a/test/hash_collision_test.cpp +++ b/test/hash_collision_test.cpp @@ -7,6 +7,7 @@ int main() { std::string token; while (std::cin >> token) { hash_t hsh = SplitMix64Hash(token); + std::cout << "hash of " << token << " is " << hsh << std::endl; if (storage.find(hsh) == storage.end()) { storage[hsh] = token; } else if (storage[hsh] != token) {