Skip to content

Executioner Protocol

RunningArmy6 edited this page Nov 18, 2026 · 2 revisions

Colossus v2.8.2 β€” Final Lock Purge & Repository Cleanup Engine

A lock system requires more than detecting invalid or obsolete records. It must also ensure that their associated runtime data, physical block metadata and repository entries are properly handled.

SecureAutoSmartLocks (SASL) uses the Executioner Engine as its centralized purge execution component.

Executioner processes queued lock identities, coordinates physical cleanup, handles chunk availability and finalizes repository persistence.

It serves as the final cleanup stage of the lock lifecycle.


βš“ 1. Purge Execution Architecture

Executioner begins its operation through executeFinalPurge(List<String> keys).

The method receives a collection of lock keys that require final processing.

Before starting, it performs two important checks:

  • Rejects null or empty key collections.
  • Uses an atomic execution flag to prevent overlapping purge operations.

Once execution begins, the engine initializes its processing state:

  • A concurrent set of processed lock keys.
  • An asynchronous chunk-load counter.
  • A shutdown/finalization guard.
  • A per-chunk reference counter.
  • A set of chunks currently involved in maintenance.

These structures allow the engine to coordinate multiple cleanup operations without starting another purge sequence simultaneously.


⚑ 2. Adaptive Batch Processing

Executioner does not process the entire key collection in one uninterrupted operation.

Instead, it uses a scheduled Bukkit task to process keys in batches.

The batch limit is calculated dynamically through calculateDynamicBatchSize().

The purge configuration provides four batch profiles:

  • batchHigh
  • batchMed
  • batchLow
  • batchCritical

The selected batch limit determines how many keys can be processed during an individual scheduler execution.

This approach divides large cleanup operations into smaller processing intervals instead of attempting to handle every key in a single pass.

Each key is validated before processing:

  1. Empty or null keys are skipped.
  2. The key is converted into a SmartLockKey.
  3. Invalid identities or unavailable world references are skipped.
  4. The target chunk coordinates are resolved.
  5. The key enters the cleanup pipeline.

Executioner also checks the pending-break state before continuing. Keys already handled by the break-purge path can be excluded from the current finalization batch.


🧹 3. Repository, RAM & Pending-State Cleanup

Before physical chunk processing, Executioner invokes clearLockData() for the current key.

This stage handles the lock's associated cleanup state.

The implementation includes:

  • Repository lock-data removal.
  • Runtime cache removal and invalidation.
  • Pending purge-state cleanup.
  • Pending PDC write cancellation through the chunk manager.

The pending-write cleanup is particularly important.

A previously queued PDC write must not recreate obsolete lock information after the corresponding lock has entered its purge sequence.

This is part of SASL's resurrection-prevention approach.


🌍 4. Chunk-Aware Execution

Executioner uses two separate processing paths depending on whether the target chunk is already loaded.

Synchronous Path β€” Loaded Chunks

When the target chunk is loaded, Executioner delegates to:

processSyncPurge()

The method:

  1. Resolves the target block.
  2. Checks whether the physical block is lockable.
  3. Identifies a structural partner when applicable.
  4. Processes the partner's associated lock data.
  5. Performs physical cleanup.

The partner lookup is handled through the Lock Service, allowing supported multi-block structures to participate in the same purge operation.

Asynchronous Path β€” Unloaded Chunks

When the target chunk is not loaded, Executioner delegates to:

processAsyncPurge()

It requests the chunk through:

world.getChunkAtAsync(cX, cZ, false)

The false argument prevents the request from generating a previously nonexistent chunk.

After the asynchronous request completes, the Bukkit scheduler is used to execute the required world and block operations.

If the chunk cannot be obtained or is not loaded when the callback runs, the corresponding reference and pending-operation counters are cleaned up.

This separates asynchronous chunk acquisition from the Bukkit-side physical cleanup work.


πŸ”— 5. Multi-Block Purge Coordination

Executioner accounts for supported structures that contain more than one physical block.

When a valid target block has a partner, the engine:

  • Resolves the partner through the Lock Service.
  • Generates the partner's coordinate key.
  • Checks whether the partner is already pending purge.
  • Removes its associated lock data when eligible.
  • Adds the partner key to the processed-key collection.
  • Registers it in the processing-purge state.

This prevents the cleanup process from treating the two halves of a supported structure as completely unrelated operations.

Physical Cleanup

The cleanPhysicalLock() method delegates the physical removal to:

LockService.fullUnlock()

It processes the main block and, when applicable, its partner.

The physical cleanup is separated from the short locksMutex section used for partner detection and repository-related coordination.

This reduces the time spent holding the lock-state mutex while physical block metadata is being modified.


πŸ›‘οΈ 6. Chunk Maintenance & Reference Tracking

Executioner tracks chunks involved in active purge operations.

It uses:

  • chunksUnderMaintenance
  • chunkRefCounter
  • localChunksTouched

Each processing operation increments the corresponding chunk reference count.

When an operation completes, cleanupChunkRef() decrements the count.

Once the count reaches zero, the chunk can be removed from the maintenance set.

This prevents a chunk from being marked as actively maintained while its associated purge work is still being processed.

The same cleanup routine is used by the synchronous and asynchronous execution paths.


πŸ’Ύ 7. Repository Finalization

After all input keys have been processed, Executioner waits for outstanding asynchronous chunk operations to finish.

Once the pending asynchronous count reaches zero, the engine calls:

finalizePurgeOperation()

The finalization process uses an atomic guard to prevent duplicate completion.

Repository Persistence

The engine obtains the active Lock Repository and performs:

  1. markDirty()
  2. saveAsync(true)

This delegates the final persistence operation to the repository layer.

Temporary-State Release

After the configured save delay, Executioner schedules the final cleanup task.

The task removes processed keys from:

  • Processing-purge tracking.
  • The purge queue.
  • The pending purge set.
  • The break-purge set.

It also releases the affected chunk maintenance entries.

Finally, it clears local tracking structures and resets the purge-running flag.

A completion message is written to the server log with the number of processed keys.


πŸ”„ 8. Execution Flow

The overall process can be represented as follows:

  1. Receive purge keys.
  2. Validate the request and acquire the execution guard.
  3. Load purge configuration.
  4. Initialize concurrent processing structures.
  5. Process keys through adaptive batches.
  6. Clear repository, RAM and pending-write state.
  7. Determine target chunk availability.
  8. Execute synchronous or asynchronous chunk processing.
  9. Resolve and clean structural partner blocks.
  10. Wait for outstanding asynchronous operations.
  11. Mark the repository dirty and schedule persistence.
  12. Release temporary purge and chunk-maintenance state.

πŸ’Ž Core Responsibilities

  • Centralized Purging: Processes lock identities through one coordinated execution pipeline.
  • Adaptive Processing: Uses configurable batch profiles and dynamic batch sizing.
  • Chunk Awareness: Separates loaded-chunk and unloaded-chunk processing.
  • No Forced Generation: Uses asynchronous chunk acquisition with generation disabled.
  • Structural Cleanup: Accounts for supported multi-block partners.
  • State Coordination: Tracks active purge keys and chunks under maintenance.
  • Repository Integration: Delegates final persistence to the Lock Repository.
  • Pending-Write Protection: Removes obsolete queued PDC writes during cleanup.
  • Controlled Finalization: Waits for outstanding asynchronous work before releasing execution state.

Architected by Protocol-S Development
Lead Dev: RunningArmy6

Clone this wiki locally