Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add proto-definitions and update table structure #3660

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export interface ILocalLogRepository extends IRepository<LocalLog, string> {
readLastestLog(sessionID: string): Promise<LocalLog>;
create(log: LocalLog): Promise<LocalLog>;
deleteBySessionId(log: string): any;
fetchLogsFromSequence(
sessionId: string,
sequenceNumber: number,
): Promise<LocalLog[]>;
destroy(): any;
reset(): any;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ export class KnexLocalLogRepository implements ILocalLogRepository {
.groupBy("sessionID");
}

fetchLogsFromSequence(
sessionId: string,
sequenceNumber: number,
): Promise<LocalLog[]> {
return this.getLogsTable()
.where("sessionID", sessionId)
.andWhere("sequenceNumber", ">", sequenceNumber);
}

async reset() {
await this.database.migrate.rollback();
await this.database.migrate.latest();
Expand Down
Loading