mirror of
https://github.com/nicotsx/ironmount.git
synced 2025-12-10 12:10:51 +01:00
Compare commits
2 Commits
v0.15.0-be
...
v0.15.0-be
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7ff38f0128 | ||
|
|
33e6f3773b |
@@ -49,8 +49,7 @@ class RepositoryMutex {
|
||||
async acquireShared(repositoryId: string, operation: string): Promise<() => void> {
|
||||
const state = this.getOrCreateState(repositoryId);
|
||||
|
||||
const hasExclusiveWaiter = state.waitQueue.some((w) => w.type === "exclusive");
|
||||
if (!state.exclusiveHolder && !hasExclusiveWaiter) {
|
||||
if (!state.exclusiveHolder) {
|
||||
const lockId = this.generateLockId();
|
||||
state.sharedHolders.set(lockId, {
|
||||
id: lockId,
|
||||
@@ -60,7 +59,9 @@ class RepositoryMutex {
|
||||
return () => this.releaseShared(repositoryId, lockId);
|
||||
}
|
||||
|
||||
logger.debug(`[Mutex] Waiting for shared lock on repo ${repositoryId}: ${operation}`);
|
||||
logger.debug(
|
||||
`[Mutex] Waiting for shared lock on repo ${repositoryId}: ${operation} (exclusive held by: ${state.exclusiveHolder.operation})`,
|
||||
);
|
||||
const lockId = await new Promise<string>((resolve) => {
|
||||
state.waitQueue.push({ type: "shared", operation, resolve });
|
||||
});
|
||||
|
||||
@@ -263,12 +263,7 @@ const executeBackup = async (scheduleId: number, manual = false) => {
|
||||
}
|
||||
|
||||
if (schedule.retentionPolicy) {
|
||||
const releaseForgetLock = await repoMutex.acquireExclusive(repository.id, `forget:${volume.name}`);
|
||||
try {
|
||||
await restic.forget(repository.config, schedule.retentionPolicy, { tag: schedule.id.toString() });
|
||||
} finally {
|
||||
releaseForgetLock();
|
||||
}
|
||||
void runForget(schedule.id);
|
||||
}
|
||||
|
||||
const nextBackupAt = calculateNextRun(schedule.cronExpression);
|
||||
@@ -415,7 +410,7 @@ const runForget = async (scheduleId: number) => {
|
||||
throw new NotFoundError("Repository not found");
|
||||
}
|
||||
|
||||
logger.info(`Manually running retention policy (forget) for schedule ${scheduleId}`);
|
||||
logger.info(`running retention policy (forget) for schedule ${scheduleId}`);
|
||||
const releaseLock = await repoMutex.acquireExclusive(repository.id, `forget:manual:${scheduleId}`);
|
||||
try {
|
||||
await restic.forget(repository.config, schedule.retentionPolicy, { tag: schedule.id.toString() });
|
||||
|
||||
Reference in New Issue
Block a user