@peerbit/shared-log 8.0.7 → 9.0.0-55cebfe
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/dist/benchmark/get-samples.d.ts +2 -0
- package/dist/benchmark/get-samples.d.ts.map +1 -0
- package/dist/benchmark/get-samples.js +69 -0
- package/dist/benchmark/get-samples.js.map +1 -0
- package/dist/benchmark/index.d.ts +2 -0
- package/dist/benchmark/index.d.ts.map +1 -0
- package/{lib/esm/__benchmark__ → dist/benchmark}/index.js +16 -16
- package/dist/benchmark/index.js.map +1 -0
- package/dist/benchmark/replication-prune.d.ts +2 -0
- package/dist/benchmark/replication-prune.d.ts.map +1 -0
- package/dist/benchmark/replication-prune.js +103 -0
- package/dist/benchmark/replication-prune.js.map +1 -0
- package/dist/benchmark/replication.d.ts +2 -0
- package/dist/benchmark/replication.d.ts.map +1 -0
- package/dist/benchmark/replication.js +91 -0
- package/dist/benchmark/replication.js.map +1 -0
- package/{lib/esm → dist/src}/blocks.d.ts +1 -0
- package/dist/src/blocks.d.ts.map +1 -0
- package/{lib/esm → dist/src}/blocks.js +1 -1
- package/dist/src/blocks.js.map +1 -0
- package/{lib/esm → dist/src}/cpu.d.ts +2 -1
- package/dist/src/cpu.d.ts.map +1 -0
- package/{lib/esm → dist/src}/cpu.js +2 -2
- package/dist/src/cpu.js.map +1 -0
- package/{lib/esm → dist/src}/exchange-heads.d.ts +2 -1
- package/dist/src/exchange-heads.d.ts.map +1 -0
- package/{lib/esm → dist/src}/exchange-heads.js +9 -7
- package/dist/src/exchange-heads.js.map +1 -0
- package/{lib/esm → dist/src}/index.d.ts +64 -54
- package/dist/src/index.d.ts.map +1 -0
- package/{lib/esm → dist/src}/index.js +569 -399
- package/dist/src/index.js.map +1 -0
- package/{lib/esm → dist/src}/message.d.ts +1 -0
- package/dist/src/message.d.ts.map +1 -0
- package/{lib/esm → dist/src}/pid.d.ts +1 -0
- package/dist/src/pid.d.ts.map +1 -0
- package/{lib/esm → dist/src}/pid.js +20 -20
- package/dist/src/pid.js.map +1 -0
- package/dist/src/ranges.d.ts +10 -0
- package/dist/src/ranges.d.ts.map +1 -0
- package/dist/src/ranges.js +645 -0
- package/dist/src/ranges.js.map +1 -0
- package/dist/src/replication.d.ts +112 -0
- package/dist/src/replication.d.ts.map +1 -0
- package/dist/src/replication.js +348 -0
- package/dist/src/replication.js.map +1 -0
- package/dist/src/role.d.ts +2 -0
- package/dist/src/role.d.ts.map +1 -0
- package/dist/src/role.js +106 -0
- package/dist/src/role.js.map +1 -0
- package/package.json +70 -43
- package/src/blocks.ts +1 -1
- package/src/cpu.ts +7 -6
- package/src/exchange-heads.ts +19 -19
- package/src/index.ts +881 -609
- package/src/pid.ts +22 -21
- package/src/ranges.ts +692 -148
- package/src/replication.ts +271 -19
- package/src/role.ts +63 -83
- package/LICENSE +0 -202
- package/lib/esm/__benchmark__/index.d.ts +0 -1
- package/lib/esm/__benchmark__/index.js.map +0 -1
- package/lib/esm/blocks.js.map +0 -1
- package/lib/esm/cpu.js.map +0 -1
- package/lib/esm/exchange-heads.js.map +0 -1
- package/lib/esm/index.js.map +0 -1
- package/lib/esm/pid.js.map +0 -1
- package/lib/esm/ranges.d.ts +0 -12
- package/lib/esm/ranges.js +0 -247
- package/lib/esm/ranges.js.map +0 -1
- package/lib/esm/replication.d.ts +0 -53
- package/lib/esm/replication.js +0 -105
- package/lib/esm/replication.js.map +0 -1
- package/lib/esm/role.d.ts +0 -38
- package/lib/esm/role.js +0 -130
- package/lib/esm/role.js.map +0 -1
- package/src/__benchmark__/index.ts +0 -115
- /package/{lib/esm → dist/src}/message.js +0 -0
- /package/{lib/esm → dist/src}/message.js.map +0 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { PublicSignKey } from "@peerbit/crypto";
|
|
2
|
+
import { type Index } from "@peerbit/indexer-interface";
|
|
3
|
+
import { TransportMessage } from "./message.js";
|
|
4
|
+
export type ReplicationLimits = {
|
|
5
|
+
min: MinReplicas;
|
|
6
|
+
max?: MinReplicas;
|
|
7
|
+
};
|
|
8
|
+
export declare enum ReplicationIntent {
|
|
9
|
+
Explicit = 0,
|
|
10
|
+
Automatic = 1
|
|
11
|
+
}
|
|
12
|
+
export declare const getSegmentsFromOffsetAndRange: (offset: number, factor: number) => [[number, number], [number, number]];
|
|
13
|
+
export declare class ReplicationRange {
|
|
14
|
+
private id;
|
|
15
|
+
timestamp: bigint;
|
|
16
|
+
private _offset;
|
|
17
|
+
private _factor;
|
|
18
|
+
constructor(properties: {
|
|
19
|
+
id: Uint8Array;
|
|
20
|
+
offset: number;
|
|
21
|
+
factor: number;
|
|
22
|
+
timestamp: bigint;
|
|
23
|
+
});
|
|
24
|
+
get factor(): number;
|
|
25
|
+
get offset(): number;
|
|
26
|
+
toReplicationRangeIndexable(key: PublicSignKey): ReplicationRangeIndexable;
|
|
27
|
+
}
|
|
28
|
+
export declare class ReplicationRangeIndexable {
|
|
29
|
+
id: Uint8Array;
|
|
30
|
+
hash: string;
|
|
31
|
+
timestamp: bigint;
|
|
32
|
+
start1: number;
|
|
33
|
+
end1: number;
|
|
34
|
+
start2: number;
|
|
35
|
+
end2: number;
|
|
36
|
+
width: number;
|
|
37
|
+
replicationIntent: ReplicationIntent;
|
|
38
|
+
constructor(properties: {
|
|
39
|
+
id?: Uint8Array;
|
|
40
|
+
offset: number;
|
|
41
|
+
length: number;
|
|
42
|
+
replicationIntent?: ReplicationIntent;
|
|
43
|
+
timestamp?: bigint;
|
|
44
|
+
} & ({
|
|
45
|
+
publicKeyHash: string;
|
|
46
|
+
} | {
|
|
47
|
+
publicKey: PublicSignKey;
|
|
48
|
+
}));
|
|
49
|
+
private transform;
|
|
50
|
+
contains(point: number): boolean;
|
|
51
|
+
overlaps(other: ReplicationRangeIndexable, checkOther?: boolean): boolean;
|
|
52
|
+
toReplicationRange(): ReplicationRange;
|
|
53
|
+
distanceTo(point: number): number;
|
|
54
|
+
get wrapped(): boolean;
|
|
55
|
+
get widthNormalized(): number;
|
|
56
|
+
equals(other: ReplicationRangeIndexable): boolean;
|
|
57
|
+
toString(): string;
|
|
58
|
+
}
|
|
59
|
+
interface SharedLog {
|
|
60
|
+
replicas: Partial<ReplicationLimits>;
|
|
61
|
+
replicationIndex: Index<ReplicationRangeIndexable> | undefined;
|
|
62
|
+
}
|
|
63
|
+
export declare class MinReplicas {
|
|
64
|
+
getValue(log: SharedLog): number;
|
|
65
|
+
}
|
|
66
|
+
export declare class AbsoluteReplicas extends MinReplicas {
|
|
67
|
+
_value: number;
|
|
68
|
+
constructor(value: number);
|
|
69
|
+
getValue(_log: SharedLog): number;
|
|
70
|
+
}
|
|
71
|
+
export declare class RequestReplicationInfoMessage extends TransportMessage {
|
|
72
|
+
constructor();
|
|
73
|
+
}
|
|
74
|
+
export declare class ResponseReplicationInfoMessage extends TransportMessage {
|
|
75
|
+
segments: ReplicationRange[];
|
|
76
|
+
constructor(properties: {
|
|
77
|
+
segments: ReplicationRange[];
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
export declare class StartedReplicating extends TransportMessage {
|
|
81
|
+
segments: ReplicationRange[];
|
|
82
|
+
constructor(properties: {
|
|
83
|
+
segments: ReplicationRange[];
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
export declare class StoppedReplicating extends TransportMessage {
|
|
87
|
+
segmentIds: Uint8Array[];
|
|
88
|
+
constructor(properties: {
|
|
89
|
+
segmentIds: Uint8Array[];
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
export declare const encodeReplicas: (minReplicas: MinReplicas) => Uint8Array;
|
|
93
|
+
export declare class ReplicationError extends Error {
|
|
94
|
+
constructor(message: string);
|
|
95
|
+
}
|
|
96
|
+
export declare const decodeReplicas: (entry: {
|
|
97
|
+
meta: {
|
|
98
|
+
data?: Uint8Array;
|
|
99
|
+
};
|
|
100
|
+
}) => MinReplicas;
|
|
101
|
+
export declare const maxReplicas: (log: SharedLog, entries: {
|
|
102
|
+
meta: {
|
|
103
|
+
data?: Uint8Array;
|
|
104
|
+
};
|
|
105
|
+
}[] | IterableIterator<{
|
|
106
|
+
meta: {
|
|
107
|
+
data?: Uint8Array;
|
|
108
|
+
};
|
|
109
|
+
}>) => number;
|
|
110
|
+
export declare const hashToUniformNumber: (hash: Uint8Array) => number;
|
|
111
|
+
export {};
|
|
112
|
+
//# sourceMappingURL=replication.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replication.d.ts","sourceRoot":"","sources":["../../src/replication.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,aAAa,EAAuB,MAAM,iBAAiB,CAAC;AACrE,OAAO,EAAE,KAAK,KAAK,EAAM,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAGhD,MAAM,MAAM,iBAAiB,GAAG;IAAE,GAAG,EAAE,WAAW,CAAC;IAAC,GAAG,CAAC,EAAE,WAAW,CAAA;CAAE,CAAC;AAqBxE,oBAAY,iBAAiB;IAC5B,QAAQ,IAAI;IACZ,SAAS,IAAI;CACb;AAED,eAAO,MAAM,6BAA6B,WACjC,MAAM,UACN,MAAM,KACZ,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAUrC,CAAC;AAEF,qBAAa,gBAAgB;IAE5B,OAAO,CAAC,EAAE,CAAa;IAGvB,SAAS,EAAE,MAAM,CAAC;IAGlB,OAAO,CAAC,OAAO,CAAS;IAGxB,OAAO,CAAC,OAAO,CAAS;gBAEZ,UAAU,EAAE;QACvB,EAAE,EAAE,UAAU,CAAC;QACf,MAAM,EAAE,MAAM,CAAC;QACf,MAAM,EAAE,MAAM,CAAC;QACf,SAAS,EAAE,MAAM,CAAC;KAClB;IAQD,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,2BAA2B,CAAC,GAAG,EAAE,aAAa,GAAG,yBAAy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AS,GAAG,MAAM;CAGjC;AAED,qBACa,6BAA8B,SAAQ,gBAAgB;;CAIlE;AAED,qBACa,8BAA+B,SAAQ,gBAAgB;IAEnE,QAAQ,EAAE,gBAAgB,EAAE,CAAC;gBAEjB,UAAU,EAAE;QAAE,QAAQ,EAAE,gBAAgB,EAAE,CAAA;KAAE;CAIxD;AAED,qBACa,kBAAmB,SAAQ,gBAAgB;IAEvD,QAAQ,EAAE,gBAAgB,EAAE,CAAC;gBAEjB,UAAU,EAAE;QAAE,QAAQ,EAAE,gBAAgB,EAAE,CAAA;KAAE;CAIxD;AAED,qBACa,kBAAmB,SAAQ,gBAAgB;IAEvD,UAAU,EAAE,UAAU,EAAE,CAAC;gBAEb,UAAU,EAAE;QAAE,UAAU,EAAE,UAAU,EAAE,CAAA;KAAE;CAIpD;AAiBD,eAAO,MAAM,cAAc,gBAAiB,WAAW,KAAG,UAEzD,CAAC;AAEF,qBAAa,gBAAiB,SAAQ,KAAK;gBAC9B,OAAO,EAAE,MAAM;CAG3B;AACD,eAAO,MAAM,cAAc,UAAW;IACrC,IAAI,EAAE;QAAE,IAAI,CAAC,EAAE,UAAU,CAAA;KAAE,CAAC;CAC5B,KAAG,WAKH,CAAC;AAEF,eAAO,MAAM,WAAW,QAClB,SAAS,WAEX;IAAE,IAAI,EAAE;QAAE,IAAI,CAAC,EAAE,UAAU,CAAA;KAAE,CAAA;CAAE,EAAE,GACjC,gBAAgB,CAAC;IAAE,IAAI,EAAE;QAAE,IAAI,CAAC,EAAE,UAAU,CAAA;KAAE,CAAA;CAAE,CAAC,WAUpD,CAAC;AAEF,eAAO,MAAM,mBAAmB,SAAU,UAAU,WAKnD,CAAC"}
|
|
@@ -0,0 +1,348 @@
|
|
|
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 { BinaryReader, deserialize, field, serialize, variant, vec, } from "@dao-xyz/borsh";
|
|
11
|
+
import { PublicSignKey, equals, randomBytes } from "@peerbit/crypto";
|
|
12
|
+
import { id } from "@peerbit/indexer-interface";
|
|
13
|
+
import { TransportMessage } from "./message.js";
|
|
14
|
+
import { SEGMENT_COORDINATE_SCALE } from "./role.js";
|
|
15
|
+
/*
|
|
16
|
+
export class ReplicatorRect {
|
|
17
|
+
|
|
18
|
+
@id({ type: Uint8Array })
|
|
19
|
+
id: Uint8Array;
|
|
20
|
+
|
|
21
|
+
@field({ type: 'string' })
|
|
22
|
+
hash: string;
|
|
23
|
+
|
|
24
|
+
@field({ type: vec(ReplicationSegment) })
|
|
25
|
+
segments: ReplicationSegment[];
|
|
26
|
+
|
|
27
|
+
constructor(properties: { hash: string; segments: ReplicationSegment[] }) {
|
|
28
|
+
this.id = randomBytes(32);
|
|
29
|
+
this.hash = properties.hash;
|
|
30
|
+
this.segments = properties.segments;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
*/
|
|
34
|
+
export var ReplicationIntent;
|
|
35
|
+
(function (ReplicationIntent) {
|
|
36
|
+
ReplicationIntent[ReplicationIntent["Explicit"] = 0] = "Explicit";
|
|
37
|
+
ReplicationIntent[ReplicationIntent["Automatic"] = 1] = "Automatic";
|
|
38
|
+
})(ReplicationIntent || (ReplicationIntent = {}));
|
|
39
|
+
export const getSegmentsFromOffsetAndRange = (offset, factor) => {
|
|
40
|
+
let start1 = offset;
|
|
41
|
+
let end1Unscaled = offset + factor; // only add factor if it is not 1 to prevent numerical issues (like (0.9 + 1) % 1 => 0.8999999)
|
|
42
|
+
let end1 = Math.min(end1Unscaled, 1);
|
|
43
|
+
return [
|
|
44
|
+
[start1, end1],
|
|
45
|
+
end1Unscaled > 1
|
|
46
|
+
? [0, (factor !== 1 ? offset + factor : offset) % 1]
|
|
47
|
+
: [start1, end1],
|
|
48
|
+
];
|
|
49
|
+
};
|
|
50
|
+
export class ReplicationRange {
|
|
51
|
+
id;
|
|
52
|
+
timestamp;
|
|
53
|
+
_offset;
|
|
54
|
+
_factor;
|
|
55
|
+
constructor(properties) {
|
|
56
|
+
const { id, offset, factor, timestamp } = properties;
|
|
57
|
+
this.id = id;
|
|
58
|
+
this._offset = Math.round(offset * SEGMENT_COORDINATE_SCALE);
|
|
59
|
+
this._factor = Math.round(factor * SEGMENT_COORDINATE_SCALE);
|
|
60
|
+
this.timestamp = timestamp;
|
|
61
|
+
}
|
|
62
|
+
get factor() {
|
|
63
|
+
return this._factor / SEGMENT_COORDINATE_SCALE;
|
|
64
|
+
}
|
|
65
|
+
get offset() {
|
|
66
|
+
return this._offset / SEGMENT_COORDINATE_SCALE;
|
|
67
|
+
}
|
|
68
|
+
toReplicationRangeIndexable(key) {
|
|
69
|
+
return new ReplicationRangeIndexable({
|
|
70
|
+
id: this.id,
|
|
71
|
+
publicKeyHash: key.hashcode(),
|
|
72
|
+
offset: this.offset,
|
|
73
|
+
length: this.factor,
|
|
74
|
+
timestamp: this.timestamp,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
__decorate([
|
|
79
|
+
field({ type: Uint8Array }),
|
|
80
|
+
__metadata("design:type", Uint8Array)
|
|
81
|
+
], ReplicationRange.prototype, "id", void 0);
|
|
82
|
+
__decorate([
|
|
83
|
+
field({ type: "u64" }),
|
|
84
|
+
__metadata("design:type", BigInt)
|
|
85
|
+
], ReplicationRange.prototype, "timestamp", void 0);
|
|
86
|
+
__decorate([
|
|
87
|
+
field({ type: "u32" }),
|
|
88
|
+
__metadata("design:type", Number)
|
|
89
|
+
], ReplicationRange.prototype, "_offset", void 0);
|
|
90
|
+
__decorate([
|
|
91
|
+
field({ type: "u32" }),
|
|
92
|
+
__metadata("design:type", Number)
|
|
93
|
+
], ReplicationRange.prototype, "_factor", void 0);
|
|
94
|
+
export class ReplicationRangeIndexable {
|
|
95
|
+
id;
|
|
96
|
+
hash;
|
|
97
|
+
timestamp;
|
|
98
|
+
start1;
|
|
99
|
+
end1;
|
|
100
|
+
start2;
|
|
101
|
+
end2;
|
|
102
|
+
width;
|
|
103
|
+
replicationIntent;
|
|
104
|
+
constructor(properties) {
|
|
105
|
+
this.id = properties.id ?? randomBytes(32);
|
|
106
|
+
this.hash =
|
|
107
|
+
properties.publicKeyHash ||
|
|
108
|
+
properties.publicKey.hashcode();
|
|
109
|
+
this.transform({ length: properties.length, offset: properties.offset });
|
|
110
|
+
this.replicationIntent =
|
|
111
|
+
properties.replicationIntent ?? ReplicationIntent.Explicit;
|
|
112
|
+
this.timestamp = properties.timestamp || BigInt(0);
|
|
113
|
+
}
|
|
114
|
+
transform(properties) {
|
|
115
|
+
const ranges = getSegmentsFromOffsetAndRange(properties.offset, properties.length);
|
|
116
|
+
this.start1 = Math.round(ranges[0][0] * SEGMENT_COORDINATE_SCALE);
|
|
117
|
+
this.end1 = Math.round(ranges[0][1] * SEGMENT_COORDINATE_SCALE);
|
|
118
|
+
this.start2 = Math.round(ranges[1][0] * SEGMENT_COORDINATE_SCALE);
|
|
119
|
+
this.end2 = Math.round(ranges[1][1] * SEGMENT_COORDINATE_SCALE);
|
|
120
|
+
this.width =
|
|
121
|
+
this.end1 -
|
|
122
|
+
this.start1 +
|
|
123
|
+
(this.end2 < this.end1 ? this.end2 - this.start2 : 0);
|
|
124
|
+
if (this.start1 > 0xffffffff ||
|
|
125
|
+
this.end1 > 0xffffffff ||
|
|
126
|
+
this.start2 > 0xffffffff ||
|
|
127
|
+
this.end2 > 0xffffffff ||
|
|
128
|
+
this.width > 0xffffffff) {
|
|
129
|
+
throw new Error("Segment coordinate out of bounds");
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
contains(point) {
|
|
133
|
+
return ((point >= this.start1 && point < this.end1) ||
|
|
134
|
+
(point >= this.start2 && point < this.end2));
|
|
135
|
+
}
|
|
136
|
+
overlaps(other, checkOther = true) {
|
|
137
|
+
if (this.contains(other.start1) ||
|
|
138
|
+
this.contains(other.start2) ||
|
|
139
|
+
this.contains(other.end1) ||
|
|
140
|
+
this.contains(other.end2)) {
|
|
141
|
+
return true;
|
|
142
|
+
}
|
|
143
|
+
if (checkOther) {
|
|
144
|
+
return other.overlaps(this, false);
|
|
145
|
+
}
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
toReplicationRange() {
|
|
149
|
+
return new ReplicationRange({
|
|
150
|
+
id: this.id,
|
|
151
|
+
offset: this.start1 / SEGMENT_COORDINATE_SCALE,
|
|
152
|
+
factor: this.width / SEGMENT_COORDINATE_SCALE,
|
|
153
|
+
timestamp: this.timestamp,
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
distanceTo(point) {
|
|
157
|
+
let wrappedPoint = SEGMENT_COORDINATE_SCALE - point;
|
|
158
|
+
return Math.min(Math.abs(this.start1 - point), Math.abs(this.end2 - point), Math.abs(this.start1 - wrappedPoint), Math.abs(this.end2 - wrappedPoint));
|
|
159
|
+
}
|
|
160
|
+
get wrapped() {
|
|
161
|
+
return this.end2 < this.end1;
|
|
162
|
+
}
|
|
163
|
+
get widthNormalized() {
|
|
164
|
+
return this.width / SEGMENT_COORDINATE_SCALE;
|
|
165
|
+
}
|
|
166
|
+
equals(other) {
|
|
167
|
+
if (equals(this.id, other.id) &&
|
|
168
|
+
this.hash === other.hash &&
|
|
169
|
+
this.timestamp === other.timestamp &&
|
|
170
|
+
this.replicationIntent === other.replicationIntent &&
|
|
171
|
+
this.start1 === other.start1 &&
|
|
172
|
+
this.end1 === other.end1 &&
|
|
173
|
+
this.start2 === other.start2 &&
|
|
174
|
+
this.end2 === other.end2 &&
|
|
175
|
+
this.width === other.width) {
|
|
176
|
+
return true;
|
|
177
|
+
}
|
|
178
|
+
return false;
|
|
179
|
+
}
|
|
180
|
+
toString() {
|
|
181
|
+
let roundToTwoDecimals = (num) => Math.round(num * 100) / 100;
|
|
182
|
+
if (Math.abs(this.start1 - this.start2) < 0.0001) {
|
|
183
|
+
return `([${roundToTwoDecimals(this.start1 / SEGMENT_COORDINATE_SCALE)}, ${roundToTwoDecimals(this.end1 / SEGMENT_COORDINATE_SCALE)}])`;
|
|
184
|
+
}
|
|
185
|
+
return `([${roundToTwoDecimals(this.start1 / SEGMENT_COORDINATE_SCALE)}, ${roundToTwoDecimals(this.end1 / SEGMENT_COORDINATE_SCALE)}] [${roundToTwoDecimals(this.start2 / SEGMENT_COORDINATE_SCALE)}, ${roundToTwoDecimals(this.end2 / SEGMENT_COORDINATE_SCALE)}])`;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
__decorate([
|
|
189
|
+
id({ type: Uint8Array }),
|
|
190
|
+
__metadata("design:type", Uint8Array)
|
|
191
|
+
], ReplicationRangeIndexable.prototype, "id", void 0);
|
|
192
|
+
__decorate([
|
|
193
|
+
field({ type: "string" }),
|
|
194
|
+
__metadata("design:type", String)
|
|
195
|
+
], ReplicationRangeIndexable.prototype, "hash", void 0);
|
|
196
|
+
__decorate([
|
|
197
|
+
field({ type: "u64" }),
|
|
198
|
+
__metadata("design:type", BigInt)
|
|
199
|
+
], ReplicationRangeIndexable.prototype, "timestamp", void 0);
|
|
200
|
+
__decorate([
|
|
201
|
+
field({ type: "u32" }),
|
|
202
|
+
__metadata("design:type", Number)
|
|
203
|
+
], ReplicationRangeIndexable.prototype, "start1", void 0);
|
|
204
|
+
__decorate([
|
|
205
|
+
field({ type: "u32" }),
|
|
206
|
+
__metadata("design:type", Number)
|
|
207
|
+
], ReplicationRangeIndexable.prototype, "end1", void 0);
|
|
208
|
+
__decorate([
|
|
209
|
+
field({ type: "u32" }),
|
|
210
|
+
__metadata("design:type", Number)
|
|
211
|
+
], ReplicationRangeIndexable.prototype, "start2", void 0);
|
|
212
|
+
__decorate([
|
|
213
|
+
field({ type: "u32" }),
|
|
214
|
+
__metadata("design:type", Number)
|
|
215
|
+
], ReplicationRangeIndexable.prototype, "end2", void 0);
|
|
216
|
+
__decorate([
|
|
217
|
+
field({ type: "u32" }),
|
|
218
|
+
__metadata("design:type", Number)
|
|
219
|
+
], ReplicationRangeIndexable.prototype, "width", void 0);
|
|
220
|
+
__decorate([
|
|
221
|
+
field({ type: "u8" }),
|
|
222
|
+
__metadata("design:type", Number)
|
|
223
|
+
], ReplicationRangeIndexable.prototype, "replicationIntent", void 0);
|
|
224
|
+
export class MinReplicas {
|
|
225
|
+
getValue(log) {
|
|
226
|
+
throw new Error("Not implemented");
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
let AbsoluteReplicas = class AbsoluteReplicas extends MinReplicas {
|
|
230
|
+
_value;
|
|
231
|
+
constructor(value) {
|
|
232
|
+
super();
|
|
233
|
+
this._value = value;
|
|
234
|
+
}
|
|
235
|
+
getValue(_log) {
|
|
236
|
+
return this._value;
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
__decorate([
|
|
240
|
+
field({ type: "u32" }),
|
|
241
|
+
__metadata("design:type", Number)
|
|
242
|
+
], AbsoluteReplicas.prototype, "_value", void 0);
|
|
243
|
+
AbsoluteReplicas = __decorate([
|
|
244
|
+
variant(0),
|
|
245
|
+
__metadata("design:paramtypes", [Number])
|
|
246
|
+
], AbsoluteReplicas);
|
|
247
|
+
export { AbsoluteReplicas };
|
|
248
|
+
let RequestReplicationInfoMessage = class RequestReplicationInfoMessage extends TransportMessage {
|
|
249
|
+
constructor() {
|
|
250
|
+
super();
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
RequestReplicationInfoMessage = __decorate([
|
|
254
|
+
variant([1, 0]),
|
|
255
|
+
__metadata("design:paramtypes", [])
|
|
256
|
+
], RequestReplicationInfoMessage);
|
|
257
|
+
export { RequestReplicationInfoMessage };
|
|
258
|
+
let ResponseReplicationInfoMessage = class ResponseReplicationInfoMessage extends TransportMessage {
|
|
259
|
+
segments;
|
|
260
|
+
constructor(properties) {
|
|
261
|
+
super();
|
|
262
|
+
this.segments = properties.segments;
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
__decorate([
|
|
266
|
+
field({ type: vec(ReplicationRange) }),
|
|
267
|
+
__metadata("design:type", Array)
|
|
268
|
+
], ResponseReplicationInfoMessage.prototype, "segments", void 0);
|
|
269
|
+
ResponseReplicationInfoMessage = __decorate([
|
|
270
|
+
variant([1, 1]),
|
|
271
|
+
__metadata("design:paramtypes", [Object])
|
|
272
|
+
], ResponseReplicationInfoMessage);
|
|
273
|
+
export { ResponseReplicationInfoMessage };
|
|
274
|
+
let StartedReplicating = class StartedReplicating extends TransportMessage {
|
|
275
|
+
segments;
|
|
276
|
+
constructor(properties) {
|
|
277
|
+
super();
|
|
278
|
+
this.segments = properties.segments;
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
__decorate([
|
|
282
|
+
field({ type: vec(ReplicationRange) }),
|
|
283
|
+
__metadata("design:type", Array)
|
|
284
|
+
], StartedReplicating.prototype, "segments", void 0);
|
|
285
|
+
StartedReplicating = __decorate([
|
|
286
|
+
variant([1, 2]),
|
|
287
|
+
__metadata("design:paramtypes", [Object])
|
|
288
|
+
], StartedReplicating);
|
|
289
|
+
export { StartedReplicating };
|
|
290
|
+
let StoppedReplicating = class StoppedReplicating extends TransportMessage {
|
|
291
|
+
segmentIds;
|
|
292
|
+
constructor(properties) {
|
|
293
|
+
super();
|
|
294
|
+
this.segmentIds = properties.segmentIds;
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
__decorate([
|
|
298
|
+
field({ type: vec(Uint8Array) }),
|
|
299
|
+
__metadata("design:type", Array)
|
|
300
|
+
], StoppedReplicating.prototype, "segmentIds", void 0);
|
|
301
|
+
StoppedReplicating = __decorate([
|
|
302
|
+
variant([1, 3]),
|
|
303
|
+
__metadata("design:paramtypes", [Object])
|
|
304
|
+
], StoppedReplicating);
|
|
305
|
+
export { StoppedReplicating };
|
|
306
|
+
/*
|
|
307
|
+
@variant(1)
|
|
308
|
+
export class RelativeMinReplicas extends MinReplicas {
|
|
309
|
+
_value: number; // (0, 1]
|
|
310
|
+
|
|
311
|
+
constructor(value: number) {
|
|
312
|
+
super();
|
|
313
|
+
this._value = value;
|
|
314
|
+
}
|
|
315
|
+
getValue(log: SharedLog): number {
|
|
316
|
+
return Math.ceil(this._value * log.getReplicatorsSorted()!.length); // TODO TYPES
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
*/
|
|
320
|
+
export const encodeReplicas = (minReplicas) => {
|
|
321
|
+
return serialize(minReplicas);
|
|
322
|
+
};
|
|
323
|
+
export class ReplicationError extends Error {
|
|
324
|
+
constructor(message) {
|
|
325
|
+
super(message);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
export const decodeReplicas = (entry) => {
|
|
329
|
+
if (!entry.meta.data) {
|
|
330
|
+
throw new ReplicationError("Missing meta data from error");
|
|
331
|
+
}
|
|
332
|
+
return deserialize(entry.meta.data, MinReplicas);
|
|
333
|
+
};
|
|
334
|
+
export const maxReplicas = (log, entries) => {
|
|
335
|
+
let max = 0;
|
|
336
|
+
for (const entry of entries) {
|
|
337
|
+
max = Math.max(decodeReplicas(entry).getValue(log), max);
|
|
338
|
+
}
|
|
339
|
+
const lower = log.replicas.min?.getValue(log) || 1;
|
|
340
|
+
const higher = log.replicas.max?.getValue(log) ?? Number.MAX_SAFE_INTEGER;
|
|
341
|
+
const numberOfLeaders = Math.max(Math.min(higher, max), lower);
|
|
342
|
+
return numberOfLeaders;
|
|
343
|
+
};
|
|
344
|
+
export const hashToUniformNumber = (hash) => {
|
|
345
|
+
const seedNumber = new BinaryReader(hash.subarray(hash.length - 4, hash.length)).u32();
|
|
346
|
+
return seedNumber / 0xffffffff; // bounded between 0 and 1
|
|
347
|
+
};
|
|
348
|
+
//# sourceMappingURL=replication.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replication.js","sourceRoot":"","sources":["../../src/replication.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EACN,YAAY,EACZ,WAAW,EACX,KAAK,EACL,SAAS,EACT,OAAO,EACP,GAAG,GACH,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACrE,OAAO,EAAc,EAAE,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,wBAAwB,EAAE,MAAM,WAAW,CAAC;AAGrD;;;;;;;;;;;;;;;;;;GAkBG;AAEH,MAAM,CAAN,IAAY,iBAGX;AAHD,WAAY,iBAAiB;IAC5B,iEAAY,CAAA;IACZ,mEAAa,CAAA;AACd,CAAC,EAHW,iBAAiB,KAAjB,iBAAiB,QAG5B;AAED,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAC5C,MAAc,EACd,MAAc,EACyB,EAAE;IACzC,IAAI,MAAM,GAAG,MAAM,CAAC;IACpB,IAAI,YAAY,GAAG,MAAM,GAAG,MAAM,CAAC,CAAC,+FAA+F;IACnI,IAAI,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC;IACrC,OAAO;QACN,CAAC,MAAM,EAAE,IAAI,CAAC;QACd,YAAY,GAAG,CAAC;YACf,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACpD,CAAC,C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","sources":["../../src/role.ts"],"names":[],"mappings":"AAiCA,eAAO,MAAM,wBAAwB,aAAa,CAAC"}
|
package/dist/src/role.js
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/* import { field, variant, vec } from "@dao-xyz/borsh"; */
|
|
2
|
+
/* export const overlaps = (x1: number, x2: number, y1: number, y2: number) => {
|
|
3
|
+
if (x1 <= y2 && y1 <= x2) {
|
|
4
|
+
return true;
|
|
5
|
+
}
|
|
6
|
+
return false;
|
|
7
|
+
}; */
|
|
8
|
+
/* export abstract class Role {
|
|
9
|
+
abstract equals(other: Role): boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const NO_TYPE_VARIANT = new Uint8Array([0]);
|
|
13
|
+
|
|
14
|
+
@variant(0)
|
|
15
|
+
export class NoType extends Role {
|
|
16
|
+
equals(other: Role) {
|
|
17
|
+
return other instanceof NoType;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const OBSERVER_TYPE_VARIANT = new Uint8Array([1]);
|
|
22
|
+
|
|
23
|
+
@variant(1)
|
|
24
|
+
export class Observer extends Role {
|
|
25
|
+
equals(other: Role) {
|
|
26
|
+
return other instanceof Observer;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const REPLICATOR_TYPE_VARIANT = new Uint8Array([2]);*/
|
|
31
|
+
export const SEGMENT_COORDINATE_SCALE = 4294967295;
|
|
32
|
+
/* export class ReplicationSegment {
|
|
33
|
+
|
|
34
|
+
@field({ type: "u64" })
|
|
35
|
+
timestamp: bigint;
|
|
36
|
+
|
|
37
|
+
@field({ type: "u32" })
|
|
38
|
+
start: number;
|
|
39
|
+
|
|
40
|
+
@field({ type: 'u32' })
|
|
41
|
+
end: number;
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
constructor(properties: {
|
|
46
|
+
start: number;
|
|
47
|
+
end: number;
|
|
48
|
+
timestamp: bigint;
|
|
49
|
+
}) {
|
|
50
|
+
const { start, end, timestamp } = properties;
|
|
51
|
+
|
|
52
|
+
if (start > end) {
|
|
53
|
+
throw new Error("Range 'start' needs to be lower or equal to 'end'")
|
|
54
|
+
}
|
|
55
|
+
this.start = Math.round(start * SEGMENT_COORDINATE_SCALE);
|
|
56
|
+
this.end = Math.round(end * SEGMENT_COORDINATE_SCALE);
|
|
57
|
+
this.timestamp = timestamp
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
}
|
|
63
|
+
*/
|
|
64
|
+
/* abstract class Capacity { }
|
|
65
|
+
|
|
66
|
+
@variant(2)
|
|
67
|
+
export class Replicator extends Role {
|
|
68
|
+
|
|
69
|
+
@field({ type: vec(Capacity) })
|
|
70
|
+
capacity: Capacity[];
|
|
71
|
+
|
|
72
|
+
constructor(properties?: { capacity: Capacity[] }) {
|
|
73
|
+
super();
|
|
74
|
+
this.capacity = properties?.capacity || [];
|
|
75
|
+
} */
|
|
76
|
+
/* constructor(properties: {
|
|
77
|
+
timestamp?: bigint;
|
|
78
|
+
factor: number;
|
|
79
|
+
offset: number;
|
|
80
|
+
}) {
|
|
81
|
+
super();
|
|
82
|
+
let timestamp = properties.timestamp || BigInt(+new Date);
|
|
83
|
+
let ranges = getSegmentsFromOffsetAndRange(properties.offset, properties.factor);
|
|
84
|
+
this.segments = ranges.map(x => new ReplicationSegment({ start: x[0], end: x[1], timestamp }));
|
|
85
|
+
}
|
|
86
|
+
*/
|
|
87
|
+
/* get factor(): number {
|
|
88
|
+
return this.segments[0]!.factor;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
get offset(): number {
|
|
92
|
+
return this.segments[0]!.offset;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
get timestamp(): bigint {
|
|
96
|
+
return this.segments[0]!.timestamp;
|
|
97
|
+
} */
|
|
98
|
+
/* equals(other: Role) {
|
|
99
|
+
return (
|
|
100
|
+
other instanceof Replicator &&
|
|
101
|
+
other.factor === this.factor &&
|
|
102
|
+
other.offset === this.offset
|
|
103
|
+
);
|
|
104
|
+
} */
|
|
105
|
+
/* } */
|
|
106
|
+
//# sourceMappingURL=role.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"role.js","sourceRoot":"","sources":["../../src/role.ts"],"names":[],"mappings":"AAAA,2DAA2D;AAE3D;;;;;KAKK;AAEL;;;;;;;;;;;;;;;;;;;;;;6DAsB6D;AAE7D,MAAM,CAAC,MAAM,wBAAwB,GAAG,UAAU,CAAC;AACnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH;;;;;;;;;;;QAWK;AAEL;;;;;;;;;;EAUE;AACF;;;;;;;;;;IAUI;AAEJ;;;;;;IAMI;AACJ,OAAO"}
|