From c3ac88fc241b3a11671a6688a27e77d462f53d29 Mon Sep 17 00:00:00 2001 From: Yogesh01000100 Date: Fri, 29 Nov 2024 12:09:55 +0000 Subject: [PATCH] feat: add proto-definitions and update table structure Signed-off-by: Yogesh01000100 --- .../20220331132128_create_logs_table.ts | 1 + .../proto/cacti/satp/v02/crash_recovery.proto | 78 ++++++++++++++++++- .../repository/interfaces/repository.ts | 5 ++ .../repository/knex-local-log-repository.ts | 15 ++++ 4 files changed, 98 insertions(+), 1 deletion(-) diff --git a/packages/cactus-plugin-satp-hermes/src/knex/migrations/20220331132128_create_logs_table.ts b/packages/cactus-plugin-satp-hermes/src/knex/migrations/20220331132128_create_logs_table.ts index cbccd817200..6227cc4aada 100644 --- a/packages/cactus-plugin-satp-hermes/src/knex/migrations/20220331132128_create_logs_table.ts +++ b/packages/cactus-plugin-satp-hermes/src/knex/migrations/20220331132128_create_logs_table.ts @@ -8,6 +8,7 @@ export function up(knex: Knex): Knex.SchemaBuilder { table.string("operation").notNullable(); table.string("timestamp").notNullable(); table.string("data").notNullable(); + table.bigInteger("sequenceNumber").notNullable(); }); } diff --git a/packages/cactus-plugin-satp-hermes/src/main/proto/cacti/satp/v02/crash_recovery.proto b/packages/cactus-plugin-satp-hermes/src/main/proto/cacti/satp/v02/crash_recovery.proto index 7f6f71c15ca..6ba42bc554d 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/proto/cacti/satp/v02/crash_recovery.proto +++ b/packages/cactus-plugin-satp-hermes/src/main/proto/cacti/satp/v02/crash_recovery.proto @@ -4,10 +4,86 @@ package cacti.satp.v02.crash; import "google/protobuf/empty.proto"; -// TODO: Rollback and crash-recovery related service CrashRecovery { // util RPCs // step RPCs + rpc RecoverV2Message(RecoverMessage) returns (RecoverUpdateMessage); + rpc RecoverV2SuccessMessage(RecoverSuccessMessage) returns (google.protobuf.Empty); + rpc RollbackV2Message(RollbackMessage) returns (RollbackAckMessage); +} + +message RecoverMessage { + string session_id = 1; + string message_type = 2; + string satp_phase = 3; + int32 sequence_number = 4; + bool is_backup = 5; + string new_identity_public_key = 6; + int64 last_entry_timestamp = 7; + string sender_signature = 8; +} + +message RecoverUpdateMessage { + string session_id = 1; + string message_type = 2; + string hash_recover_message = 3; + repeated LocalLog recovered_logs = 4; + string sender_signature = 5; +} + +message RecoverSuccessMessage { + string session_id = 1; + string message_type = 2; + string hash_recover_update_message = 3; + bool success = 4; + repeated string entries_changed = 5; + string sender_signature = 6; +} + +message RollbackMessage { + string session_id = 1; + string message_type = 2; + bool success = 3; + repeated string actions_performed = 4; + repeated string proofs = 5; + string sender_signature = 6; +} + +message RollbackAckMessage { + string session_id = 1; + string message_type = 2; + bool success = 3; + repeated string actions_performed = 4; + repeated string proofs = 5; + string sender_signature = 6; +} + +message LocalLog { + string session_id = 1; + string type = 2; + string key = 3; + string operation = 4; + string timestamp = 5; + string data = 6; + int32 sequence_number = 7; +} + +message RollbackLogEntry { + string session_id = 1; + string stage = 2; + string timestamp = 3; + string action = 4; // action performed during rollback + string status = 5; // status of rollback (e.g., SUCCESS, FAILED) + string details = 6; // Additional details or metadata about the rollback +} +message RollbackState { + string session_id = 1; + string current_stage = 2; + int32 steps_remaining = 3; + repeated RollbackLogEntry rollback_log_entries = 4; + string estimated_time_to_completion = 5; + string status = 6; // Overall status (e.g., IN_PROGRESS, COMPLETED, FAILED) + string details = 7; // Additional metadata or information } diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/repository/interfaces/repository.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/repository/interfaces/repository.ts index 8d1524398fa..b5b947c6ad3 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/repository/interfaces/repository.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/repository/interfaces/repository.ts @@ -15,6 +15,11 @@ export interface ILocalLogRepository extends IRepository { readLastestLog(sessionID: string): Promise; create(log: LocalLog): Promise; deleteBySessionId(log: string): any; + fetchLogsFromSequence( + sessionId: string, + sequenceNumber: number, + ): Promise; + readLogsBySessionId(sessionId: string): Promise; destroy(): any; reset(): any; } diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/repository/knex-local-log-repository.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/repository/knex-local-log-repository.ts index e5a71a4d9c9..0d9dd60c4ff 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/repository/knex-local-log-repository.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/repository/knex-local-log-repository.ts @@ -54,6 +54,21 @@ export class KnexLocalLogRepository implements ILocalLogRepository { .groupBy("sessionID"); } + fetchLogsFromSequence( + sessionId: string, + sequenceNumber: number, + ): Promise { + return this.getLogsTable() + .where("sessionID", sessionId) + .andWhere("sequenceNumber", ">", sequenceNumber); + } + + readLogsBySessionId(sessionId: string): Promise { + return this.getLogsTable() + .where({ sessionID: sessionId }) + .orderBy("timestamp", "asc"); + } + async reset() { await this.database.migrate.rollback(); await this.database.migrate.latest();