From 757c98422dfb888bea9ca2795c51fb5201ced251 Mon Sep 17 00:00:00 2001 From: AayushSaini101 Date: Sun, 31 Aug 2025 11:19:10 +0530 Subject: [PATCH 1/3] chore: add retry functionality in the systemDb connection --- dbos/dbos.go | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/dbos/dbos.go b/dbos/dbos.go index c9013818..9d91f803 100644 --- a/dbos/dbos.go +++ b/dbos/dbos.go @@ -101,15 +101,15 @@ type DBOSContext interface { Shutdown(timeout time.Duration) // Gracefully shutdown all DBOS runtime components with ordered cleanup sequence // Workflow operations - RunAsStep(_ DBOSContext, fn StepFunc, opts ...StepOption) (any, error) // Execute a function as a durable step within a workflow + RunAsStep(_ DBOSContext, fn StepFunc, opts ...StepOption) (any, error) // Execute a function as a durable step within a workflow RunWorkflow(_ DBOSContext, fn WorkflowFunc, input any, opts ...WorkflowOption) (WorkflowHandle[any], error) // Start a new workflow execution - Send(_ DBOSContext, destinationID string, message any, topic string) error // Send a message to another workflow - Recv(_ DBOSContext, topic string, timeout time.Duration) (any, error) // Receive a message sent to this workflow - SetEvent(_ DBOSContext, key string, message any) error // Set a key-value event for this workflow - GetEvent(_ DBOSContext, targetWorkflowID string, key string, timeout time.Duration) (any, error) // Get a key-value event from a target workflow - Sleep(_ DBOSContext, duration time.Duration) (time.Duration, error) // Durable sleep that survives workflow recovery - GetWorkflowID() (string, error) // Get the current workflow ID (only available within workflows) - GetStepID() (int, error) // Get the current step ID (only available within workflows) + Send(_ DBOSContext, destinationID string, message any, topic string) error // Send a message to another workflow + Recv(_ DBOSContext, topic string, timeout time.Duration) (any, error) // Receive a message sent to this workflow + SetEvent(_ DBOSContext, key string, message any) error // Set a key-value event for this workflow + GetEvent(_ DBOSContext, targetWorkflowID string, key string, timeout time.Duration) (any, error) // Get a key-value event from a target workflow + Sleep(_ DBOSContext, duration time.Duration) (time.Duration, error) // Durable sleep that survives workflow recovery + GetWorkflowID() (string, error) // Get the current workflow ID (only available within workflows) + GetStepID() (int, error) // Get the current step ID (only available within workflows) // Workflow management RetrieveWorkflow(_ DBOSContext, workflowID string) (WorkflowHandle[any], error) // Get a handle to an existing workflow @@ -317,12 +317,28 @@ func NewDBOSContext(inputConfig Config) (DBOSContext, error) { initExecutor.executorID = config.ExecutorID initExecutor.applicationID = os.Getenv("DBOS__APPID") + maxRetries := 5 + retryDelay := time.Second * 2 + + var systemDB systemDatabase + + for attempt := 1; attempt <= maxRetries; attempt++ { + systemDB, err = newSystemDatabase(initExecutor, config.DatabaseURL, initExecutor.logger) + if err == nil { + break + } + initExecutor.logger.Warn("Failed to connect to system DB (attempt %d/%d): %v", attempt, maxRetries, err) + + if attempt < maxRetries { + time.Sleep(retryDelay) + retryDelay *= 2 // Exponential backoff + } + } - // Create the system database - systemDB, err := newSystemDatabase(initExecutor, config.DatabaseURL, initExecutor.logger) if err != nil { - return nil, newInitializationError(fmt.Sprintf("failed to create system database: %v", err)) + return nil, newInitializationError(fmt.Sprintf("failed to create system database after %d attempts: %v", maxRetries, err)) } + initExecutor.systemDB = systemDB initExecutor.logger.Info("System database initialized") From 6d51c73b07d58f5d3d4ab12c5d9e57be0b2cbdda Mon Sep 17 00:00:00 2001 From: AayushSaini101 Date: Sun, 31 Aug 2025 11:32:05 +0530 Subject: [PATCH 2/3] Improve logging statements --- .idea/.gitignore | 10 ++++++++++ .idea/dbos-transact-golang.iml | 10 ++++++++++ .idea/misc.xml | 6 ++++++ .idea/modules.xml | 8 ++++++++ .idea/vcs.xml | 6 ++++++ dbos/dbos.go | 2 +- 6 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/dbos-transact-golang.iml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 00000000..7bc07ec2 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,10 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Environment-dependent path to Maven home directory +/mavenHomeManager.xml +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/dbos-transact-golang.iml b/.idea/dbos-transact-golang.iml new file mode 100644 index 00000000..25ed3f6e --- /dev/null +++ b/.idea/dbos-transact-golang.iml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 00000000..07115cdf --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 00000000..5d5582a9 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..35eb1ddf --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/dbos/dbos.go b/dbos/dbos.go index 9d91f803..8832b6ad 100644 --- a/dbos/dbos.go +++ b/dbos/dbos.go @@ -327,7 +327,7 @@ func NewDBOSContext(inputConfig Config) (DBOSContext, error) { if err == nil { break } - initExecutor.logger.Warn("Failed to connect to system DB (attempt %d/%d): %v", attempt, maxRetries, err) + initExecutor.logger.Warn("Failed to connect to system DB", "attempt", attempt, "maxRetries", maxRetries, "error", err) if attempt < maxRetries { time.Sleep(retryDelay) From 02894419a56468d3e46c5281a428ffc2de8050d2 Mon Sep 17 00:00:00 2001 From: AayushSaini101 Date: Mon, 1 Sep 2025 08:05:34 +0530 Subject: [PATCH 3/3] Remove .idea folder --- .idea/.gitignore | 10 ---------- .idea/dbos-transact-golang.iml | 10 ---------- .idea/misc.xml | 6 ------ .idea/modules.xml | 8 -------- .idea/vcs.xml | 6 ------ 5 files changed, 40 deletions(-) delete mode 100644 .idea/.gitignore delete mode 100644 .idea/dbos-transact-golang.iml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 7bc07ec2..00000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,10 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Editor-based HTTP Client requests -/httpRequests/ -# Environment-dependent path to Maven home directory -/mavenHomeManager.xml -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml diff --git a/.idea/dbos-transact-golang.iml b/.idea/dbos-transact-golang.iml deleted file mode 100644 index 25ed3f6e..00000000 --- a/.idea/dbos-transact-golang.iml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 07115cdf..00000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 5d5582a9..00000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 35eb1ddf..00000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file