java.lang.Object
net.i2p.router.JobImpl
net.i2p.router.tunnel.pool.ExpireJob
- All Implemented Interfaces:
Job
Handles tunnel expiration in two phases for graceful shutdown. Uses batch processing to reduce job queue overhead. First run removes tunnel from LeaseSet and triggers refresh. Second run stops accepting data for the tunnel entirely. Uses randomized early expiration with different timing for inbound vs outbound tunnels.
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classOne tunnel tracked for expiration.Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final ConcurrentHashMap<Long, ExpireJob.TunnelExpiration> The tunnels being expired, by tunnel key.private static booleanTrue while the job is scheduled.private static final intBuild failures counting as backed up.private static final longExpiration window handled per run.private static final longHow early inbound tunnels are replaced.private static final longKeep tunnels alive for 10 minutes after LeaseSet refresh so clients with cached (stale) LeaseSets can still connect using old tunnel IDs.private static final longLongest an entry may stay in the map.private static final intEntries examined when pools are short.private static final intEntries examined per normal run.(package private) static final intMaximum number of times an UNTESTED tunnel's expiry can be extended to give tests time to complete.private static final longHow early outbound tunnels are replaced.(package private) static final longHow long to extend an UNTESTED tunnel's expiry each time.Constructor Summary
ConstructorsModifierConstructorDescriptionprivateExpireJob(RouterContext ctx) Constructor for the batch job, with no tunnel config.Method Summary
Modifier and TypeMethodDescription(package private) static StringexpirationLine(long key, long expire, long dropAt, long now) The entry recording when a tunnel expires and when it is dropped for good, as durations from now rather than raw epoch milliseconds.getName()Descriptive name of the task.static LongGet the unique key for this tunnel config.static voidRemove a tunnel from the expiration queue.voidrunJob()Actually perform the task.private voidRuns one expiration phase.static voidSchedule a tunnel for batched expiration.Methods inherited from class JobImpl
dropped, getContext, getJobId, getMadeReadyOn, getTiming, madeReady, requeue, toStringModifier and TypeMethodDescriptionvoiddropped()Default implementation does nothing.final RouterContextThe router context that this job belongs to.longgetJobId()The unique job ID for this job.longThe timestamp when this job was last made ready for execution.The timing object for this job.voidmadeReady(long now) For JobQueue only, not for external use.protected voidrequeue(long delayMs) Requeue this job to run after the specified delay.toString()
Field Details
_expirations
The tunnels being expired, by tunnel key._isScheduled
private static volatile boolean _isScheduledTrue while the job is scheduled.BATCH_WINDOW
private static final long BATCH_WINDOWExpiration window handled per run.- See Also:
OB_EARLY_EXPIRE
private static final long OB_EARLY_EXPIREHow early outbound tunnels are replaced.- See Also:
IB_EARLY_EXPIRE
private static final long IB_EARLY_EXPIREHow early inbound tunnels are replaced.- See Also:
LEASESET_GRACE_PERIOD
private static final long LEASESET_GRACE_PERIODKeep tunnels alive for 10 minutes after LeaseSet refresh so clients with cached (stale) LeaseSets can still connect using old tunnel IDs.- See Also:
MAX_ENTRY_LIFETIME
private static final long MAX_ENTRY_LIFETIMELongest an entry may stay in the map. With early expiration the entries live about 21 minutes; the extra time covers clock skew and slow job execution.- See Also:
MAX_ITERATE_PER_RUN
private static final int MAX_ITERATE_PER_RUNEntries examined per normal run.- See Also:
MAX_ITERATE_BACKED_UP
private static final int MAX_ITERATE_BACKED_UPEntries examined when pools are short.- See Also:
BACKED_UP_THRESHOLD
private static final int BACKED_UP_THRESHOLDBuild failures counting as backed up.- See Also:
MAX_UNTESTED_EXTENSIONS
static final int MAX_UNTESTED_EXTENSIONSMaximum number of times an UNTESTED tunnel's expiry can be extended to give tests time to complete. Each extension isUNTESTED_EXTENSION_MS.- See Also:
UNTESTED_EXTENSION_MS
static final long UNTESTED_EXTENSION_MSHow long to extend an UNTESTED tunnel's expiry each time. 30s gives the test pipeline enough time for one full test cycle.- See Also:
Constructor Details
ExpireJob
Constructor for the batch job, with no tunnel config.- Parameters:
ctx- the router context
Method Details
getName
scheduleExpiration
Schedule a tunnel for batched expiration. Applies randomized early expiration to reduce the chance of LeaseSet/tunnel mismatch during the transition period. If the tunnel is already scheduled with a later expiration (e.g. by BuildExecutor at build completion), an earlier expiration set by the caller on the config is merged in so early-expiry paths (slow-tunnel removal, budget pruning) actually take effect.- Parameters:
ctx- the router contextcfg- the tunnel config to expire
expirationLine
The entry recording when a tunnel expires and when it is dropped for good, as durations from now rather than raw epoch milliseconds.- Parameters:
key- the tunnel's id, as used in the expiration mapexpire- when phase 1 replaces the tunnel, in msdropAt- when the tunnel is dropped, in msnow- the current time, in ms- Returns:
- the log entry, never null
removeFromExpiration
Remove a tunnel from the expiration queue. Called during pool shutdown to prevent memory leaks.- Parameters:
cfg- config to remove
getTunnelKey
Get the unique key for this tunnel config. Uses tunnel IDs when available; falls back to identity hash for partially cleaned-up or zero-ID configs.- Parameters:
cfg- the tunnel config whose expiration key is wanted; may be null- Returns:
- key or null
runJob
public void runJob()Description copied from interface:JobActually perform the task. This call blocks until the Job is complete.runPhase
Runs one expiration phase.- Parameters:
log- the logger for the phasenow- the current time