@peerbit/shared-log 3.1.10 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/esm/__benchmark__/index.js +12 -3
- package/lib/esm/__benchmark__/index.js.map +1 -1
- package/lib/esm/blocks.d.ts +6 -0
- package/lib/esm/blocks.js +29 -0
- package/lib/esm/blocks.js.map +1 -0
- package/lib/esm/exchange-heads.d.ts +0 -1
- package/lib/esm/exchange-heads.js +0 -1
- package/lib/esm/exchange-heads.js.map +1 -1
- package/lib/esm/index.d.ts +101 -42
- package/lib/esm/index.js +753 -249
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/replication.d.ts +28 -5
- package/lib/esm/replication.js +37 -2
- package/lib/esm/replication.js.map +1 -1
- package/lib/esm/role.d.ts +22 -2
- package/lib/esm/role.js +57 -9
- package/lib/esm/role.js.map +1 -1
- package/package.json +9 -8
- package/src/__benchmark__/index.ts +13 -4
- package/src/blocks.ts +19 -0
- package/src/exchange-heads.ts +1 -2
- package/src/index.ts +1097 -342
- package/src/replication.ts +49 -4
- package/src/role.ts +67 -6
|
@@ -13,8 +13,10 @@ import { TestSession } from "@peerbit/test-utils";
|
|
|
13
13
|
import { v4 as uuid } from "uuid";
|
|
14
14
|
import crypto from "crypto";
|
|
15
15
|
import { Program } from "@peerbit/program";
|
|
16
|
-
import {
|
|
16
|
+
import { SharedLog } from "../index.js";
|
|
17
|
+
import { mplex } from "@libp2p/mplex";
|
|
17
18
|
// Run with "node --loader ts-node/esm ./src/__benchmark__/index.ts"
|
|
19
|
+
// put x 5,843 ops/sec ±4.50% (367 runs sampled)
|
|
18
20
|
let Document = class Document {
|
|
19
21
|
id;
|
|
20
22
|
name;
|
|
@@ -74,7 +76,11 @@ TestStore = __decorate([
|
|
|
74
76
|
__metadata("design:paramtypes", [Object])
|
|
75
77
|
], TestStore);
|
|
76
78
|
const peersCount = 1;
|
|
77
|
-
const session = await TestSession.connected(peersCount
|
|
79
|
+
const session = await TestSession.connected(peersCount, {
|
|
80
|
+
libp2p: {
|
|
81
|
+
streamMuxers: [mplex()]
|
|
82
|
+
}
|
|
83
|
+
});
|
|
78
84
|
const store = new TestStore({
|
|
79
85
|
logs: new SharedLog({
|
|
80
86
|
id: new Uint8Array(32)
|
|
@@ -83,7 +89,10 @@ const store = new TestStore({
|
|
|
83
89
|
const client = session.peers[0];
|
|
84
90
|
await client.open(store, {
|
|
85
91
|
args: {
|
|
86
|
-
role:
|
|
92
|
+
role: {
|
|
93
|
+
type: "replicator",
|
|
94
|
+
factor: 1
|
|
95
|
+
},
|
|
87
96
|
trim: { type: "length", to: 100 },
|
|
88
97
|
onChange: (change) => {
|
|
89
98
|
change.added.forEach(async (entry) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/__benchmark__/index.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,CAAC,MAAM,WAAW,CAAC;AAC1B,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAChF,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAElD,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAC;AAClC,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/__benchmark__/index.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,CAAC,MAAM,WAAW,CAAC;AAC1B,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAChF,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAElD,OAAO,EAAE,EAAE,IAAI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,KAAK,WAAsB,GAAG,IAAW;IACxD,MAAM,KAAK,CAAC,IAAI,EAAE,CAAC;IACnB,MAAM,OAAO,CAAC,IAAI,EAAE,CAAC;AACtB,CAAC,CAAC;KACD,GAAG,EAAE,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { BlockRequest, BlockResponse } from "@peerbit/blocks";
|
|
2
|
+
import { TransportMessage } from "./message.js";
|
|
3
|
+
export declare class BlocksMessage extends TransportMessage {
|
|
4
|
+
message: BlockRequest | BlockResponse;
|
|
5
|
+
constructor(message: BlockRequest | BlockResponse);
|
|
6
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { field, variant } from "@dao-xyz/borsh";
|
|
11
|
+
import { BlockMessage as IBlockMessage } from "@peerbit/blocks";
|
|
12
|
+
import { TransportMessage } from "./message.js";
|
|
13
|
+
let BlocksMessage = class BlocksMessage extends TransportMessage {
|
|
14
|
+
message;
|
|
15
|
+
constructor(message) {
|
|
16
|
+
super();
|
|
17
|
+
this.message = message;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
__decorate([
|
|
21
|
+
field({ type: IBlockMessage }),
|
|
22
|
+
__metadata("design:type", Object)
|
|
23
|
+
], BlocksMessage.prototype, "message", void 0);
|
|
24
|
+
BlocksMessage = __decorate([
|
|
25
|
+
variant([2, 0]),
|
|
26
|
+
__metadata("design:paramtypes", [Object])
|
|
27
|
+
], BlocksMessage);
|
|
28
|
+
export { BlocksMessage };
|
|
29
|
+
//# sourceMappingURL=blocks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blocks.js","sourceRoot":"","sources":["../../src/blocks.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAGN,YAAY,IAAI,aAAa,EAC7B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAGzC,IAAM,aAAa,GAAnB,MAAM,aAAc,SAAQ,gBAAgB;IAElD,OAAO,CAA+B;IAEtC,YAAY,OAAqC;QAChD,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACxB,CAAC;CACD,CAAA;AAPA;IADC,KAAK,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,CAAC;;8CACO;AAF1B,aAAa;IADzB,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;;GACH,aAAa,CASzB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exchange-heads.js","sourceRoot":"","sources":["../../src/exchange-heads.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACjE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAgB,MAAM,cAAc,CAAC;AAE9D,OAAO,EAAE,MAAM,IAAI,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAGhD,MAAM,MAA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YAAY,GAAG,GAAG,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;wBACrD,IAAI,CAAC,YAAY,EAAE,CAAC;4BACnB,MAAM,CAAC,KAAK,CAAC,yCAAyC,GAAG,IAAI,CAAC,CAAC;wBAChE,CAAC;6BAAM,CAAC;4BACP,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;wBAC1B,CAAC;oBACF,CAAC;gBACF,CAAC;YACF,CAAC;YACD,IAAI,GAAG,KAAK,CAAC;QACd,CAAC;IACF,CAAC;IACD,MAAM,KAAK,GAAG;QACb,GAAG,CAAC,MAAM,OAAO,CAAC,GAAG,CACpB,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CACxD,CAAC;KACF,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAiB,CAAC;IACrC,cAAc,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACtC,OAAO,KAAK,CAAC;AACd,CAAC,CAAC"}
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -1,103 +1,162 @@
|
|
|
1
1
|
import { RequestContext, RPC } from "@peerbit/rpc";
|
|
2
2
|
import { TransportMessage } from "./message.js";
|
|
3
3
|
import { AppendOptions, Entry, Log, LogEvents, LogProperties } from "@peerbit/log";
|
|
4
|
-
import { Program } from "@peerbit/program";
|
|
4
|
+
import { Program, ProgramEvents } from "@peerbit/program";
|
|
5
5
|
import { PublicSignKey } from "@peerbit/crypto";
|
|
6
6
|
import { SubscriptionEvent, UnsubcriptionEvent } from "@peerbit/pubsub-interface";
|
|
7
7
|
import { Observer, Replicator, Role } from "./role.js";
|
|
8
|
-
import { AbsoluteReplicas,
|
|
8
|
+
import { AbsoluteReplicas, ReplicationLimits, ReplicatorRect } from "./replication.js";
|
|
9
|
+
import yallist from "yallist";
|
|
9
10
|
export * from "./replication.js";
|
|
10
11
|
export { Observer, Replicator, Role };
|
|
11
|
-
export declare const logger: import("pino").Logger<
|
|
12
|
-
export type SyncFilter = (entries: Entry<any>) => Promise<boolean> | boolean;
|
|
13
|
-
type ReplicationLimits = {
|
|
14
|
-
min: MinReplicas;
|
|
15
|
-
max?: MinReplicas;
|
|
16
|
-
};
|
|
12
|
+
export declare const logger: import("pino").Logger<never>;
|
|
17
13
|
export type ReplicationLimitsOptions = Partial<ReplicationLimits> | {
|
|
18
14
|
min?: number;
|
|
19
15
|
max?: number;
|
|
20
16
|
};
|
|
21
|
-
|
|
17
|
+
type StringRoleOptions = "observer" | "replicator";
|
|
18
|
+
export type ReplicationErrorFunction = (objectives: {
|
|
19
|
+
coverage: number;
|
|
20
|
+
balance: number;
|
|
21
|
+
memory: number;
|
|
22
|
+
}) => number;
|
|
23
|
+
type AdaptiveReplicatorOptions = {
|
|
24
|
+
type: "replicator";
|
|
25
|
+
limits?: {
|
|
26
|
+
memory: number;
|
|
27
|
+
};
|
|
28
|
+
error?: ReplicationErrorFunction;
|
|
29
|
+
};
|
|
30
|
+
type FixedReplicatorOptions = {
|
|
31
|
+
type: "replicator";
|
|
32
|
+
factor: number;
|
|
33
|
+
};
|
|
34
|
+
type ObserverType = {
|
|
35
|
+
type: "observer";
|
|
36
|
+
};
|
|
37
|
+
export type RoleOptions = StringRoleOptions | ObserverType | FixedReplicatorOptions | AdaptiveReplicatorOptions;
|
|
38
|
+
export type SharedLogOptions = {
|
|
39
|
+
role?: RoleOptions;
|
|
22
40
|
replicas?: ReplicationLimitsOptions;
|
|
23
|
-
sync?: SyncFilter;
|
|
24
|
-
role?: Role;
|
|
25
41
|
respondToIHaveTimeout?: number;
|
|
26
42
|
canReplicate?: (publicKey: PublicSignKey) => Promise<boolean> | boolean;
|
|
27
|
-
}
|
|
43
|
+
};
|
|
28
44
|
export declare const DEFAULT_MIN_REPLICAS = 2;
|
|
45
|
+
export declare const WAIT_FOR_REPLICATOR_TIMEOUT = 9000;
|
|
46
|
+
export declare const WAIT_FOR_ROLE_MATURITY = 5000;
|
|
29
47
|
export type Args<T> = LogProperties<T> & LogEvents<T> & SharedLogOptions;
|
|
30
48
|
export type SharedAppendOptions<T> = AppendOptions<T> & {
|
|
31
49
|
replicas?: AbsoluteReplicas | number;
|
|
32
50
|
};
|
|
33
|
-
|
|
51
|
+
type UpdateRoleEvent = {
|
|
52
|
+
publicKey: PublicSignKey;
|
|
53
|
+
role: Role;
|
|
54
|
+
};
|
|
55
|
+
export interface SharedLogEvents extends ProgramEvents {
|
|
56
|
+
role: CustomEvent<UpdateRoleEvent>;
|
|
57
|
+
}
|
|
58
|
+
export declare class SharedLog<T = Uint8Array> extends Program<Args<T>, SharedLogEvents> {
|
|
34
59
|
log: Log<T>;
|
|
35
60
|
rpc: RPC<TransportMessage, TransportMessage>;
|
|
36
|
-
private _sync?;
|
|
37
61
|
private _role;
|
|
62
|
+
private _roleOptions;
|
|
38
63
|
private _sortedPeersCache;
|
|
39
|
-
private _lastSubscriptionMessageId;
|
|
40
64
|
private _gidPeersHistory;
|
|
41
65
|
private _onSubscriptionFn;
|
|
42
66
|
private _onUnsubscriptionFn;
|
|
43
67
|
private _canReplicate?;
|
|
44
68
|
private _logProperties?;
|
|
69
|
+
private _closeController;
|
|
45
70
|
private _loadedOnce;
|
|
46
71
|
private _gidParentCache;
|
|
47
72
|
private _respondToIHaveTimeout;
|
|
48
73
|
private _pendingDeletes;
|
|
49
74
|
private _pendingIHave;
|
|
75
|
+
private latestRoleMessages;
|
|
76
|
+
private remoteBlocks;
|
|
77
|
+
private openTime;
|
|
78
|
+
private rebalanceParticipationDebounced;
|
|
50
79
|
replicas: ReplicationLimits;
|
|
51
80
|
constructor(properties?: {
|
|
52
81
|
id?: Uint8Array;
|
|
53
82
|
});
|
|
54
83
|
get role(): Observer | Replicator;
|
|
55
|
-
|
|
56
|
-
|
|
84
|
+
private setupRole;
|
|
85
|
+
updateRole(role: RoleOptions, onRoleChange?: boolean): Promise<boolean>;
|
|
86
|
+
private _updateRole;
|
|
57
87
|
append(data: T, options?: SharedAppendOptions<T> | undefined): Promise<{
|
|
58
88
|
entry: Entry<T>;
|
|
59
89
|
removed: Entry<T>[];
|
|
60
90
|
}>;
|
|
61
91
|
open(options?: Args<T>): Promise<void>;
|
|
92
|
+
getMemoryUsage(): Promise<number>;
|
|
62
93
|
get topic(): string;
|
|
63
94
|
private _close;
|
|
64
95
|
close(from?: Program): Promise<boolean>;
|
|
65
96
|
drop(from?: Program): Promise<boolean>;
|
|
66
97
|
recover(): Promise<void>;
|
|
67
98
|
_onMessage(msg: TransportMessage, context: RequestContext): Promise<TransportMessage | undefined>;
|
|
68
|
-
getReplicatorsSorted():
|
|
69
|
-
|
|
70
|
-
timestamp: number;
|
|
71
|
-
}[] | undefined;
|
|
99
|
+
getReplicatorsSorted(): yallist<ReplicatorRect> | undefined;
|
|
100
|
+
waitForReplicator(...keys: PublicSignKey[]): Promise<boolean | undefined>;
|
|
72
101
|
isLeader(slot: {
|
|
73
102
|
toString(): string;
|
|
74
|
-
}, numberOfLeaders: number
|
|
103
|
+
}, numberOfLeaders: number, options?: {
|
|
104
|
+
candidates?: string[];
|
|
105
|
+
roleAge?: number;
|
|
106
|
+
}): Promise<boolean>;
|
|
107
|
+
private waitForIsLeader;
|
|
75
108
|
findLeaders(subject: {
|
|
76
109
|
toString(): string;
|
|
77
|
-
},
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
data?: Uint8Array;
|
|
82
|
-
}[], subscribed: boolean): Promise<void>;
|
|
83
|
-
pruneSafely(entries: Entry<any>[], options?: {
|
|
84
|
-
timeout: number;
|
|
85
|
-
}): Promise<any>[];
|
|
86
|
-
/**
|
|
87
|
-
* When a peers join the networkk and want to participate the leaders for particular log subgraphs might change, hence some might start replicating, might some stop
|
|
88
|
-
* This method will go through my owned entries, and see whether I should share them with a new leader, and/or I should stop care about specific entries
|
|
89
|
-
* @param channel
|
|
90
|
-
*/
|
|
91
|
-
replicationReorganization(): Promise<boolean>;
|
|
110
|
+
}, numberOfLeaders: number, options?: {
|
|
111
|
+
roleAge?: number;
|
|
112
|
+
}): Promise<string[]>;
|
|
113
|
+
private findLeadersFromUniformNumber;
|
|
92
114
|
/**
|
|
93
115
|
*
|
|
94
116
|
* @returns groups where at least one in any group will have the entry you are looking for
|
|
95
117
|
*/
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
118
|
+
getReplicatorUnion(roleAge?: number): string[];
|
|
119
|
+
replicator(entry: Entry<any>, options?: {
|
|
120
|
+
candidates?: string[];
|
|
121
|
+
roleAge?: number;
|
|
122
|
+
}): Promise<boolean>;
|
|
123
|
+
private onRoleChange;
|
|
124
|
+
private modifyReplicators;
|
|
125
|
+
private _modifyReplicators;
|
|
126
|
+
handleSubscriptionChange(publicKey: PublicSignKey, changes: string[], subscribed: boolean): Promise<void>;
|
|
127
|
+
prune(entries: Entry<any>[], options?: {
|
|
128
|
+
timeout?: number;
|
|
129
|
+
unchecked?: boolean;
|
|
130
|
+
}): Promise<any>;
|
|
131
|
+
distribute(): Promise<false | undefined>;
|
|
101
132
|
_onUnsubscription(evt: CustomEvent<UnsubcriptionEvent>): Promise<void>;
|
|
102
133
|
_onSubscription(evt: CustomEvent<SubscriptionEvent>): Promise<void>;
|
|
134
|
+
replicationController: ReplicationController;
|
|
135
|
+
history: {
|
|
136
|
+
usedMemory: number;
|
|
137
|
+
factor: number;
|
|
138
|
+
}[];
|
|
139
|
+
addToHistory(usedMemory: number, factor: number): Promise<void>;
|
|
140
|
+
calculateTrend(): Promise<number>;
|
|
141
|
+
private sumFactors;
|
|
142
|
+
rebalanceParticipation(onRoleChange?: boolean): Promise<boolean>;
|
|
143
|
+
}
|
|
144
|
+
declare class ReplicationController {
|
|
145
|
+
integral: number;
|
|
146
|
+
prevError: number;
|
|
147
|
+
prevMemoryUsage: number;
|
|
148
|
+
lastTs: number;
|
|
149
|
+
kp: number;
|
|
150
|
+
ki: number;
|
|
151
|
+
kd: number;
|
|
152
|
+
errorFunction: ReplicationErrorFunction;
|
|
153
|
+
targetMemoryLimit?: number;
|
|
154
|
+
constructor(options?: {
|
|
155
|
+
errorFunction?: ReplicationErrorFunction;
|
|
156
|
+
targetMemoryLimit?: number;
|
|
157
|
+
kp?: number;
|
|
158
|
+
ki?: number;
|
|
159
|
+
kd?: number;
|
|
160
|
+
});
|
|
161
|
+
adjustReplicationFactor(memoryUsage: number, currentFactor: number, totalFactor: number, peerCount: number): Promise<number>;
|
|
103
162
|
}
|