-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
release v3.0.0 with disk storage ability
- Loading branch information
1 parent
42d5465
commit 6c06118
Showing
23 changed files
with
838 additions
and
768 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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
lib | ||
chunks | ||
node_modules | ||
sandbox.ts | ||
.DS_Store |
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
src | ||
chunks | ||
tsconfig.json | ||
sandbox.ts | ||
.DS_Store |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
export * from './src/watchers/process.watcher' | ||
// export * from './src/data-tracker/fs.data-tracker' // TODO | ||
export * from './src/chunk-resolver' | ||
import { ChunkResolver } from './src/chunk-resolver' | ||
|
||
export * from './src/interface' | ||
export * from './src/errors' | ||
|
||
export * from './src/interface' | ||
export { ChunkResolver } |
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,92 @@ | ||
import { Chunk } from './chunk/chunk' | ||
import { ChunkId, Table } from './interface' | ||
|
||
interface ChunkState { | ||
chunkRef: Chunk, | ||
size: number, | ||
expiresAt: number | ||
} | ||
|
||
interface RegistryState { | ||
chunkTable: Record<string, string>, | ||
tableChunk: Record<string, string>, | ||
chunks: Record<ChunkId, ChunkState> | ||
} | ||
|
||
/** | ||
* InMemoryPool is a subset of ChunkPool abstraction | ||
* This pool saves rows in chunks that are stored in process memory | ||
* | ||
* @warning storing data in process memory can lead you to LOSS OF CONSISTANCE | ||
* but instead of this disadvantage you gain the cheapest and the most simple way to work | ||
* with clickhouse | ||
* | ||
* Data loss can only occur in two cases: | ||
* 1. When OS sends to a process SIGKILL code which is killing your process without grace | ||
* 2. When some piece of data contains anomalies such as `undefined` etc | ||
*/ | ||
export class ChunkRegistry { | ||
#registry: RegistryState | ||
|
||
/** | ||
* Create InMemoryPool instance | ||
*/ | ||
constructor () { | ||
this.#registry = { | ||
tableChunk: {}, | ||
chunkTable: {}, | ||
chunks: {} | ||
} | ||
} | ||
|
||
public increaseSize (id: ChunkId, delta: number) { | ||
this.#registry.chunks[id].size += delta | ||
this.#registry.chunks[id].chunkRef.size += delta | ||
} | ||
|
||
public decreaseSize (id: ChunkId, delta: number) { | ||
this.#registry.chunks[id].size -= delta | ||
this.#registry.chunks[id].chunkRef.size -= delta | ||
} | ||
|
||
public register (chunk: Chunk) { | ||
this.#registry.chunkTable[chunk.id] = chunk.table | ||
this.#registry.tableChunk[chunk.table] = chunk.id | ||
|
||
this.#registry.chunks[chunk.id] = { | ||
chunkRef: chunk, | ||
expiresAt: chunk.expiresAt, | ||
size: chunk.size | ||
} | ||
} | ||
|
||
public unregister (id: ChunkId) { | ||
if (this.#registry.chunks[id]) { | ||
const table = this.#registry.chunkTable[id] | ||
|
||
delete this.#registry.tableChunk[table] | ||
delete this.#registry.chunkTable[id] | ||
delete this.#registry.chunks[id] | ||
} | ||
} | ||
|
||
public getOne (id: ChunkId): ChunkState { | ||
return this.#registry.chunks[id] | ||
} | ||
|
||
public getAll(): ChunkState[] { | ||
return Object.values(this.#registry.chunks) | ||
} | ||
|
||
public isEmpty(): boolean { | ||
return Object.keys(this.#registry.chunks).length === 0 | ||
} | ||
|
||
public getTables(): Table[] { | ||
return Object.keys(this.#registry.tableChunk) | ||
} | ||
|
||
public getChunks(): ChunkId[] { | ||
return Object.keys(this.#registry.chunks) | ||
} | ||
} |
Oops, something went wrong.