Skip to main content

Stop Merge

Stops and finalizes a merge operation, applying all accumulated values atomically to the database.

Common Properties

  • Name - The custom name of the node.
  • Color - The custom color of the node.
  • Delay Before (sec) - Waits in seconds before executing the node.
  • Delay After (sec) - Waits in seconds after executing node.
  • Continue On Error - Automation will continue regardless of any error. The default value is false.
info

If the ContinueOnError property is true, no error is caught when the project is executed, even if a Catch node is used.

Inputs

  • Merge ID - The unique identifier of the merge operation to finalize, as returned by the Start Merge node.

How It Works

The Stop Merge node finalizes a merge operation and applies all accumulated values atomically to the database.

When executed, the node:

  1. Validates the merge ID
  2. Retrieves the merge operator
  3. Applies all accumulated values atomically
  4. Updates the database with the final result
  5. Removes the merge operator from memory
  6. Releases all associated resources
info

All values added via Merge nodes are applied together atomically when Stop Merge is called.

Examples

Example 1: Basic Counter

Complete a counter increment:

1. Start Merge
Database Id: {{db_id}}
Key: page_views
Operation Type: Increment
→ merge_id

2. Merge
Merge Id: {{merge_id}}
Value: 1

3. Stop Merge
Merge Id: {{merge_id}}

4. Get Result
Database Id: {{db_id}}
Key: page_views
→ total_views

Log "Total views: {{total_views}}"

Example 2: Inventory Decrement with Validation

Decrease inventory and verify:

1. Start Merge
Database Id: {{db_id}}
Key: product:SKU123:stock
Operation Type: Decrement
→ merge_id

2. For each order_item in {{order}}:
Merge
Merge Id: {{merge_id}}
Value: {{order_item.quantity}}

3. Stop Merge
Merge Id: {{merge_id}}

4. Get Final Stock
Database Id: {{db_id}}
Key: product:SKU123:stock
→ final_stock

5. If {{final_stock}} < 0:
Alert "Stock went negative!"

Example 3: JSON Merge with Result Check

Merge configuration and verify:

1. Start Merge
Database Id: {{db_id}}
Key: app:config
Operation Type: JSON
→ merge_id

2. Merge (defaults)
Merge Id: {{merge_id}}
Value: {"theme": "light", "language": "en"}

3. Merge (overrides)
Merge Id: {{merge_id}}
Value: {"theme": "dark"}

4. Stop Merge
Merge Id: {{merge_id}}

5. Get Configuration
Database Id: {{db_id}}
Key: app:config
→ config

Log "Final config: {{config}}"
(Result: {"theme": "dark", "language": "en"})

Example 4: Analytics Collection

Collect and finalize analytics:

1. Start Merge
Database Id: {{db_id}}
Key: analytics:daily:{{date}}
Operation Type: Increment
→ merge_id

2. For each hour in day:
Get Hourly Count
→ hourly_count
Merge
Merge Id: {{merge_id}}
Value: {{hourly_count}}

3. Stop Merge
Merge Id: {{merge_id}}

4. Get Daily Total
Database Id: {{db_id}}
Key: analytics:daily:{{date}}
→ daily_total

Log "Daily total: {{daily_total}} events"

Example 5: Error Handling

Handle merge completion with error handling:

Try:
1. Start Merge
Database Id: {{db_id}}
Key: stats:total
Operation Type: Increment
→ merge_id

2. For each value in {{values}}:
Merge
Merge Id: {{merge_id}}
Value: {{value}}

3. Stop Merge
Merge Id: {{merge_id}}

Log "Merge completed successfully"

Catch:
Log "Merge failed: {{error}}"

Tips for Effective Use

  • Always Call Stop Merge - Every Start Merge should have a Stop Merge
  • Verify Results - Use Get after Stop Merge to verify the final value
  • Handle Errors - Use try-catch to handle stop merge errors
  • Immediate Effect - Changes are applied immediately when Stop Merge executes
  • One Stop Per Merge - Each merge operation should be stopped only once
  • Check Final Values - Especially important for decrement operations

Common Errors and Solutions

Error: "merge id cannot be empty"

Solution: Ensure you're passing the merge ID from Start Merge.

Correct:
Start Merge → merge_id
Merge operations...
Stop Merge (Merge ID: {{merge_id}})

Error: Merge Operator Not Found

Solution: The merge operation doesn't exist. Ensure:

  • Start Merge was successful
  • Merge ID is correct
  • Merge operation wasn't already stopped
  • No errors occurred during Start Merge
Verify flow:
1. Start Merge → Check success → merge_id
2. Merge operations
3. Stop Merge (once only)

Error: Database Write Error

Solution: The database couldn't be updated. Check:

  • Database is still open
  • Disk space is available
  • No concurrent access conflicts
  • Database isn't corrupted

What Happens When Stop Merge is Called

For Increment Operations

  1. All merged values are summed
  2. Sum is added to current value in database
  3. Result stored atomically
  4. Example: Current=10, Merged(5+3+2)=10, Result=20

For Decrement Operations

  1. All merged values are summed
  2. Sum is subtracted from current value
  3. Result stored atomically
  4. Example: Current=100, Merged(10+20)=30, Result=70

For JSON Operations

  1. All merged objects are combined
  2. Later values override earlier ones
  3. Final merged object stored
  4. Example: {a:1} + {b:2} + {a:3} = {a:3, b:2}

Auto-Finalization

If Stop Merge is not called:

  • Merge operator is automatically finalized when the flow ends
  • Changes are applied automatically
  • No values are lost
  • Best practice: Always explicitly call Stop Merge

Performance Considerations

  • Atomic Operation - All values applied in one atomic write
  • Efficient - More efficient than multiple individual updates
  • Disk Sync - Changes synced to disk for durability
  • Memory Release - Merge operator removed from memory
  • Immediate Visibility - Changes visible immediately after Stop Merge

Best Practices

  • Explicit Stop - Always explicitly call Stop Merge for clarity
  • Verify Results - Use Get to check the final value
  • Error Handling - Wrap Stop Merge in try-catch
  • One Stop Only - Don't call Stop Merge multiple times for same merge ID
  • Document Purpose - Comment what the merge operation achieved
  • Check Constraints - Verify final values meet business rules

Merge Lifecycle

Complete Lifecycle

Start Merge → Accumulate Values (Merge) → Stop Merge → Value Applied

With Verification

Start Merge → Merge → Merge → Stop Merge → Get → Verify Result

With Error Handling

Try:
Start Merge → Merge → Stop Merge
Catch:
Handle Error

Use Cases

Use Case 1: Page View Counter

Start Merge (Increment)
Key: page:{{page_id}}:views
Merge (Value: 1)
Stop Merge

Use Case 2: Bulk Inventory Update

Start Merge (Decrement)
Key: product:{{sku}}:stock
For each sold_item:
Merge (Value: sold_item.quantity)
Stop Merge
Get stock → verify_not_negative

Use Case 3: Configuration Assembly

Start Merge (JSON)
Key: config:app
Merge (Value: base_config)
Merge (Value: env_config)
Merge (Value: user_config)
Stop Merge
Get config → active_config

Use Case 4: Statistics Rollup

Start Merge (Increment)
Key: stats:monthly:{{month}}
For each day:
Get daily_stat
Merge (Value: daily_stat)
Stop Merge

Use Case 5: Feature Metadata

Start Merge (JSON)
Key: feature:{{feature_id}}:metadata
Merge (Value: {created: timestamp})
Merge (Value: {author: user_id})
Merge (Value: {status: "active"})
Stop Merge

Verification Patterns

Pattern 1: Basic Verification

Stop Merge
Get key → result
If result != expected:
Alert "Unexpected result"

Pattern 2: Constraint Checking

Stop Merge
Get key → value
If value < 0:
Log "Warning: Negative value"

Pattern 3: Audit Trail

Stop Merge
Get key → new_value
Log "Value changed to {{new_value}}"
Create Audit Record

Atomicity Guarantee

When Stop Merge executes:

  • All accumulated values are applied together
  • Either all succeed or all fail
  • No partial updates
  • Database remains consistent

Example:

Current value: 100
Merge operations: +10, +20, +30
Stop Merge: Value becomes 160 atomically
(Not 110, then 130, then 160)
  • Start Merge - Starts the merge operation
  • Merge - Adds values to the merge operation
  • Get - Retrieves the final merged value
  • Set - Alternative for simple value updates