RunBundle executes a bundle of operations in the context of a given tenant. It returns an EncodedSnapToken upon successful completion or an error if the operation fails.
( ctx context.Context, tenantID string, arguments map[string]string, b *base.DataBundle, )
| 125 | // RunBundle executes a bundle of operations in the context of a given tenant. |
| 126 | // It returns an EncodedSnapToken upon successful completion or an error if the operation fails. |
| 127 | func (w *DataWriter) RunBundle( |
| 128 | ctx context.Context, |
| 129 | tenantID string, |
| 130 | arguments map[string]string, |
| 131 | b *base.DataBundle, |
| 132 | ) (token.EncodedSnapToken, error) { |
| 133 | // Start a new tracing span for this operation. |
| 134 | ctx, span := internal.Tracer.Start(ctx, "data-writer.run-bundle") |
| 135 | defer span.End() // Ensure that the span is ended when the function returns. |
| 136 | |
| 137 | // Log the start of running a bundle operation. |
| 138 | slog.DebugContext(ctx, "running bundle for tenant_id", slog.String("tenant_id", tenantID), "max retries", slog.Any("max_retries", w.database.GetMaxRetries())) |
| 139 | // Retry loop with backoff |
| 140 | // Retry loop for handling transient errors like serialization issues. |
| 141 | for i := 0; i <= w.database.GetMaxRetries(); i++ { |
| 142 | // Attempt to run the bundle operation. |
| 143 | tkn, err := w.runBundle(ctx, tenantID, arguments, b) |
| 144 | if err != nil { |
| 145 | // Check if the error is due to serialization, and if so, retry. |
| 146 | if utils.IsSerializationRelatedError(err) || pgconn.SafeToRetry(err) { |
| 147 | slog.WarnContext(ctx, "serialization error occurred", slog.String("tenant_id", tenantID), slog.Int("retry", i)) |
| 148 | utils.WaitWithBackoff(ctx, tenantID, i) |
| 149 | continue // Retry the operation. |
| 150 | } |
| 151 | // If the error is not serialization-related, handle it and return. |
| 152 | return nil, utils.HandleError(ctx, span, err, base.ErrorCode_ERROR_CODE_DATASTORE) |
| 153 | } |
| 154 | // If the operation is successful, return the token. |
| 155 | return tkn, nil |
| 156 | } |
| 157 | |
| 158 | // Log an error if the operation failed after reaching the maximum number of retries. |
| 159 | slog.ErrorContext(ctx, "max retries reached", slog.Any("error", errors.New(base.ErrorCode_ERROR_CODE_ERROR_MAX_RETRIES.String()))) |
| 160 | // Max retries exceeded |
| 161 | // Return an error indicating that the maximum number of retries has been reached. |
| 162 | return nil, errors.New(base.ErrorCode_ERROR_CODE_ERROR_MAX_RETRIES.String()) |
| 163 | } |
| 164 | |
| 165 | // write handles the database writing of tuple and attribute collections for a given tenant. |
| 166 | // It returns an EncodedSnapToken upon successful write or an error if the write fails. |
nothing calls this directly
no test coverage detected