-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(mapping): fix insert race conditions (#255)
* add locks to map functions * usermap and convmap map functions * fix convmap and usermap * cleanup * tests * test * more tests * barrier service * service * use barrier for convmap * usermap use barrier * tunnel use barrier * more tests * identities use barrier * sender use barrier * thread use barrier
- Loading branch information
1 parent
03e1bd4
commit 7e070eb
Showing
14 changed files
with
463 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { ServerCache2D } from '../caching/cache2D' | ||
|
||
export class Barrier2D<T> { | ||
constructor(private id: string, private locks: ServerCache2D<Promise<T>>) {} | ||
|
||
async once(keyX: string, keyY: string, callback: () => Promise<T>): Promise<T> { | ||
let promise = this.locks.get(keyX, keyY) | ||
|
||
if (!promise) { | ||
promise = new Promise(async (resolve) => { | ||
resolve(await callback()) | ||
this.locks.del(keyX, keyY) | ||
}) | ||
|
||
this.locks.set(keyX, keyY, promise) | ||
} | ||
|
||
return promise | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Service } from '../base/service' | ||
import { CachingService } from '../caching/service' | ||
import { Barrier2D } from './barrier' | ||
|
||
export class BarrierService extends Service { | ||
constructor(private caching: CachingService) { | ||
super() | ||
} | ||
|
||
async setup() {} | ||
|
||
async newBarrier2D<T>(id: string): Promise<Barrier2D<T>> { | ||
const locks = await this.caching.newServerCache2D<Promise<T>>(`cache_locks_${id}`) | ||
return new Barrier2D(id, locks) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.