@streamr/node 100.0.0-rc.0

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.
Files changed (238) hide show
  1. package/LICENSE +78 -0
  2. package/README.md +54 -0
  3. package/bin/broker.ts +36 -0
  4. package/bin/config-wizard.js +4 -0
  5. package/bin/config-wizard.ts +17 -0
  6. package/bin/delete-expired-data.ts +41 -0
  7. package/bin/entry-point.ts +27 -0
  8. package/configs/development-1.env.json +68 -0
  9. package/configs/development-2.env.json +53 -0
  10. package/configs/development-3.env.json +53 -0
  11. package/configs/development-prod-resend.env.json +21 -0
  12. package/configs/docker-1.env.json +72 -0
  13. package/configs/docker-2.env.json +58 -0
  14. package/configs/docker-3.env.json +58 -0
  15. package/configuration.md +38 -0
  16. package/dist/bin/broker.d.ts +2 -0
  17. package/dist/bin/broker.js +42 -0
  18. package/dist/bin/broker.js.map +1 -0
  19. package/dist/bin/config-wizard.d.ts +2 -0
  20. package/dist/bin/config-wizard.js +22 -0
  21. package/dist/bin/config-wizard.js.map +1 -0
  22. package/dist/bin/delete-expired-data.d.ts +2 -0
  23. package/dist/bin/delete-expired-data.js +44 -0
  24. package/dist/bin/delete-expired-data.js.map +1 -0
  25. package/dist/bin/entry-point.d.ts +2 -0
  26. package/dist/bin/entry-point.js +28 -0
  27. package/dist/bin/entry-point.js.map +1 -0
  28. package/dist/package.json +78 -0
  29. package/dist/src/Plugin.d.ts +33 -0
  30. package/dist/src/Plugin.js +43 -0
  31. package/dist/src/Plugin.js.map +1 -0
  32. package/dist/src/apiAuthentication.d.ts +4 -0
  33. package/dist/src/apiAuthentication.js +16 -0
  34. package/dist/src/apiAuthentication.js.map +1 -0
  35. package/dist/src/broker.d.ts +8 -0
  36. package/dist/src/broker.js +69 -0
  37. package/dist/src/broker.js.map +1 -0
  38. package/dist/src/config/ConfigWizard.d.ts +5 -0
  39. package/dist/src/config/ConfigWizard.js +466 -0
  40. package/dist/src/config/ConfigWizard.js.map +1 -0
  41. package/dist/src/config/config.d.ts +26 -0
  42. package/dist/src/config/config.js +92 -0
  43. package/dist/src/config/config.js.map +1 -0
  44. package/dist/src/config/config.schema.json +86 -0
  45. package/dist/src/config/definitions.schema.json +35 -0
  46. package/dist/src/config/migration.d.ts +6 -0
  47. package/dist/src/config/migration.js +210 -0
  48. package/dist/src/config/migration.js.map +1 -0
  49. package/dist/src/config/validateConfig.d.ts +4 -0
  50. package/dist/src/config/validateConfig.js +40 -0
  51. package/dist/src/config/validateConfig.js.map +1 -0
  52. package/dist/src/exports.d.ts +3 -0
  53. package/dist/src/exports.js +6 -0
  54. package/dist/src/exports.js.map +1 -0
  55. package/dist/src/helpers/PayloadFormat.d.ts +19 -0
  56. package/dist/src/helpers/PayloadFormat.js +85 -0
  57. package/dist/src/helpers/PayloadFormat.js.map +1 -0
  58. package/dist/src/helpers/applyPluginClientConfigs.d.ts +3 -0
  59. package/dist/src/helpers/applyPluginClientConfigs.js +29 -0
  60. package/dist/src/helpers/applyPluginClientConfigs.js.map +1 -0
  61. package/dist/src/helpers/fetchOrThrow.d.ts +2 -0
  62. package/dist/src/helpers/fetchOrThrow.js +20 -0
  63. package/dist/src/helpers/fetchOrThrow.js.map +1 -0
  64. package/dist/src/helpers/generateMnemonicFromAddress.d.ts +5 -0
  65. package/dist/src/helpers/generateMnemonicFromAddress.js +16 -0
  66. package/dist/src/helpers/generateMnemonicFromAddress.js.map +1 -0
  67. package/dist/src/helpers/multiply.d.ts +1 -0
  68. package/dist/src/helpers/multiply.js +10 -0
  69. package/dist/src/helpers/multiply.js.map +1 -0
  70. package/dist/src/helpers/parser.d.ts +9 -0
  71. package/dist/src/helpers/parser.js +62 -0
  72. package/dist/src/helpers/parser.js.map +1 -0
  73. package/dist/src/helpers/partitions.d.ts +8 -0
  74. package/dist/src/helpers/partitions.js +32 -0
  75. package/dist/src/helpers/partitions.js.map +1 -0
  76. package/dist/src/helpers/weightedSample.d.ts +16 -0
  77. package/dist/src/helpers/weightedSample.js +35 -0
  78. package/dist/src/helpers/weightedSample.js.map +1 -0
  79. package/dist/src/httpServer.d.ts +16 -0
  80. package/dist/src/httpServer.js +71 -0
  81. package/dist/src/httpServer.js.map +1 -0
  82. package/dist/src/pluginRegistry.d.ts +3 -0
  83. package/dist/src/pluginRegistry.js +35 -0
  84. package/dist/src/pluginRegistry.js.map +1 -0
  85. package/dist/src/plugins/consoleMetrics/ConsoleMetricsPlugin.d.ts +12 -0
  86. package/dist/src/plugins/consoleMetrics/ConsoleMetricsPlugin.js +36 -0
  87. package/dist/src/plugins/consoleMetrics/ConsoleMetricsPlugin.js.map +1 -0
  88. package/dist/src/plugins/consoleMetrics/config.schema.json +18 -0
  89. package/dist/src/plugins/http/HttpPlugin.d.ts +8 -0
  90. package/dist/src/plugins/http/HttpPlugin.js +23 -0
  91. package/dist/src/plugins/http/HttpPlugin.js.map +1 -0
  92. package/dist/src/plugins/http/config.schema.json +12 -0
  93. package/dist/src/plugins/http/publishEndpoint.d.ts +3 -0
  94. package/dist/src/plugins/http/publishEndpoint.js +72 -0
  95. package/dist/src/plugins/http/publishEndpoint.js.map +1 -0
  96. package/dist/src/plugins/info/InfoPlugin.d.ts +9 -0
  97. package/dist/src/plugins/info/InfoPlugin.js +31 -0
  98. package/dist/src/plugins/info/InfoPlugin.js.map +1 -0
  99. package/dist/src/plugins/info/config.schema.json +12 -0
  100. package/dist/src/plugins/mqtt/Bridge.d.ts +40 -0
  101. package/dist/src/plugins/mqtt/Bridge.js +136 -0
  102. package/dist/src/plugins/mqtt/Bridge.js.map +1 -0
  103. package/dist/src/plugins/mqtt/MqttPlugin.d.ts +14 -0
  104. package/dist/src/plugins/mqtt/MqttPlugin.js +30 -0
  105. package/dist/src/plugins/mqtt/MqttPlugin.js.map +1 -0
  106. package/dist/src/plugins/mqtt/MqttServer.d.ts +22 -0
  107. package/dist/src/plugins/mqtt/MqttServer.js +109 -0
  108. package/dist/src/plugins/mqtt/MqttServer.js.map +1 -0
  109. package/dist/src/plugins/mqtt/config.schema.json +26 -0
  110. package/dist/src/plugins/operator/ConsistentHashRing.d.ts +20 -0
  111. package/dist/src/plugins/operator/ConsistentHashRing.js +64 -0
  112. package/dist/src/plugins/operator/ConsistentHashRing.js.map +1 -0
  113. package/dist/src/plugins/operator/ContractFacade.d.ts +80 -0
  114. package/dist/src/plugins/operator/ContractFacade.js +364 -0
  115. package/dist/src/plugins/operator/ContractFacade.js.map +1 -0
  116. package/dist/src/plugins/operator/MaintainTopologyHelper.d.ts +23 -0
  117. package/dist/src/plugins/operator/MaintainTopologyHelper.js +75 -0
  118. package/dist/src/plugins/operator/MaintainTopologyHelper.js.map +1 -0
  119. package/dist/src/plugins/operator/MaintainTopologyService.d.ts +11 -0
  120. package/dist/src/plugins/operator/MaintainTopologyService.js +57 -0
  121. package/dist/src/plugins/operator/MaintainTopologyService.js.map +1 -0
  122. package/dist/src/plugins/operator/OperatorFleetState.d.ts +33 -0
  123. package/dist/src/plugins/operator/OperatorFleetState.js +112 -0
  124. package/dist/src/plugins/operator/OperatorFleetState.js.map +1 -0
  125. package/dist/src/plugins/operator/OperatorPlugin.d.ts +50 -0
  126. package/dist/src/plugins/operator/OperatorPlugin.js +159 -0
  127. package/dist/src/plugins/operator/OperatorPlugin.js.map +1 -0
  128. package/dist/src/plugins/operator/StreamPartAssignments.d.ts +28 -0
  129. package/dist/src/plugins/operator/StreamPartAssignments.js +104 -0
  130. package/dist/src/plugins/operator/StreamPartAssignments.js.map +1 -0
  131. package/dist/src/plugins/operator/announceNodeToContract.d.ts +3 -0
  132. package/dist/src/plugins/operator/announceNodeToContract.js +39 -0
  133. package/dist/src/plugins/operator/announceNodeToContract.js.map +1 -0
  134. package/dist/src/plugins/operator/announceNodeToStream.d.ts +3 -0
  135. package/dist/src/plugins/operator/announceNodeToStream.js +25 -0
  136. package/dist/src/plugins/operator/announceNodeToStream.js.map +1 -0
  137. package/dist/src/plugins/operator/checkOperatorValueBreach.d.ts +2 -0
  138. package/dist/src/plugins/operator/checkOperatorValueBreach.js +21 -0
  139. package/dist/src/plugins/operator/checkOperatorValueBreach.js.map +1 -0
  140. package/dist/src/plugins/operator/closeExpiredFlags.d.ts +3 -0
  141. package/dist/src/plugins/operator/closeExpiredFlags.js +24 -0
  142. package/dist/src/plugins/operator/closeExpiredFlags.js.map +1 -0
  143. package/dist/src/plugins/operator/config.schema.json +152 -0
  144. package/dist/src/plugins/operator/createIsLeaderFn.d.ts +4 -0
  145. package/dist/src/plugins/operator/createIsLeaderFn.js +14 -0
  146. package/dist/src/plugins/operator/createIsLeaderFn.js.map +1 -0
  147. package/dist/src/plugins/operator/fetchRedundancyFactor.d.ts +2 -0
  148. package/dist/src/plugins/operator/fetchRedundancyFactor.js +43 -0
  149. package/dist/src/plugins/operator/fetchRedundancyFactor.js.map +1 -0
  150. package/dist/src/plugins/operator/formCoordinationStreamId.d.ts +3 -0
  151. package/dist/src/plugins/operator/formCoordinationStreamId.js +9 -0
  152. package/dist/src/plugins/operator/formCoordinationStreamId.js.map +1 -0
  153. package/dist/src/plugins/operator/heartbeatUtils.d.ts +67 -0
  154. package/dist/src/plugins/operator/heartbeatUtils.js +26 -0
  155. package/dist/src/plugins/operator/heartbeatUtils.js.map +1 -0
  156. package/dist/src/plugins/operator/inspectOverTime.d.ts +22 -0
  157. package/dist/src/plugins/operator/inspectOverTime.js +146 -0
  158. package/dist/src/plugins/operator/inspectOverTime.js.map +1 -0
  159. package/dist/src/plugins/operator/inspectRandomNode.d.ts +8 -0
  160. package/dist/src/plugins/operator/inspectRandomNode.js +44 -0
  161. package/dist/src/plugins/operator/inspectRandomNode.js.map +1 -0
  162. package/dist/src/plugins/operator/inspectionUtils.d.ts +23 -0
  163. package/dist/src/plugins/operator/inspectionUtils.js +120 -0
  164. package/dist/src/plugins/operator/inspectionUtils.js.map +1 -0
  165. package/dist/src/plugins/operator/maintainOperatorValue.d.ts +2 -0
  166. package/dist/src/plugins/operator/maintainOperatorValue.js +21 -0
  167. package/dist/src/plugins/operator/maintainOperatorValue.js.map +1 -0
  168. package/dist/src/plugins/operator/reviewSuspectNode.d.ts +24 -0
  169. package/dist/src/plugins/operator/reviewSuspectNode.js +56 -0
  170. package/dist/src/plugins/operator/reviewSuspectNode.js.map +1 -0
  171. package/dist/src/plugins/storage/Batch.d.ts +51 -0
  172. package/dist/src/plugins/storage/Batch.js +121 -0
  173. package/dist/src/plugins/storage/Batch.js.map +1 -0
  174. package/dist/src/plugins/storage/BatchManager.d.ts +27 -0
  175. package/dist/src/plugins/storage/BatchManager.js +117 -0
  176. package/dist/src/plugins/storage/BatchManager.js.map +1 -0
  177. package/dist/src/plugins/storage/Bucket.d.ts +23 -0
  178. package/dist/src/plugins/storage/Bucket.js +90 -0
  179. package/dist/src/plugins/storage/Bucket.js.map +1 -0
  180. package/dist/src/plugins/storage/BucketManager.d.ts +56 -0
  181. package/dist/src/plugins/storage/BucketManager.js +306 -0
  182. package/dist/src/plugins/storage/BucketManager.js.map +1 -0
  183. package/dist/src/plugins/storage/DataQueryFormat.d.ts +10 -0
  184. package/dist/src/plugins/storage/DataQueryFormat.js +51 -0
  185. package/dist/src/plugins/storage/DataQueryFormat.js.map +1 -0
  186. package/dist/src/plugins/storage/DeleteExpiredCmd.d.ts +28 -0
  187. package/dist/src/plugins/storage/DeleteExpiredCmd.js +155 -0
  188. package/dist/src/plugins/storage/DeleteExpiredCmd.js.map +1 -0
  189. package/dist/src/plugins/storage/SetMembershipSynchronizer.d.ts +33 -0
  190. package/dist/src/plugins/storage/SetMembershipSynchronizer.js +102 -0
  191. package/dist/src/plugins/storage/SetMembershipSynchronizer.js.map +1 -0
  192. package/dist/src/plugins/storage/Storage.d.ts +47 -0
  193. package/dist/src/plugins/storage/Storage.js +459 -0
  194. package/dist/src/plugins/storage/Storage.js.map +1 -0
  195. package/dist/src/plugins/storage/StorageConfig.d.ts +43 -0
  196. package/dist/src/plugins/storage/StorageConfig.js +83 -0
  197. package/dist/src/plugins/storage/StorageConfig.js.map +1 -0
  198. package/dist/src/plugins/storage/StorageEventListener.d.ts +17 -0
  199. package/dist/src/plugins/storage/StorageEventListener.js +46 -0
  200. package/dist/src/plugins/storage/StorageEventListener.js.map +1 -0
  201. package/dist/src/plugins/storage/StoragePlugin.d.ts +32 -0
  202. package/dist/src/plugins/storage/StoragePlugin.js +103 -0
  203. package/dist/src/plugins/storage/StoragePlugin.js.map +1 -0
  204. package/dist/src/plugins/storage/StoragePoller.d.ts +15 -0
  205. package/dist/src/plugins/storage/StoragePoller.js +47 -0
  206. package/dist/src/plugins/storage/StoragePoller.js.map +1 -0
  207. package/dist/src/plugins/storage/config.schema.json +88 -0
  208. package/dist/src/plugins/storage/dataMetadataEndpoint.d.ts +3 -0
  209. package/dist/src/plugins/storage/dataMetadataEndpoint.js +35 -0
  210. package/dist/src/plugins/storage/dataMetadataEndpoint.js.map +1 -0
  211. package/dist/src/plugins/storage/dataQueryEndpoint.d.ts +6 -0
  212. package/dist/src/plugins/storage/dataQueryEndpoint.js +181 -0
  213. package/dist/src/plugins/storage/dataQueryEndpoint.js.map +1 -0
  214. package/dist/src/plugins/storage/storageConfigEndpoint.d.ts +3 -0
  215. package/dist/src/plugins/storage/storageConfigEndpoint.js +31 -0
  216. package/dist/src/plugins/storage/storageConfigEndpoint.js.map +1 -0
  217. package/dist/src/plugins/subscriber/SubscriberPlugin.d.ts +16 -0
  218. package/dist/src/plugins/subscriber/SubscriberPlugin.js +22 -0
  219. package/dist/src/plugins/subscriber/SubscriberPlugin.js.map +1 -0
  220. package/dist/src/plugins/subscriber/config.schema.json +31 -0
  221. package/dist/src/plugins/websocket/Connection.d.ts +9 -0
  222. package/dist/src/plugins/websocket/Connection.js +45 -0
  223. package/dist/src/plugins/websocket/Connection.js.map +1 -0
  224. package/dist/src/plugins/websocket/PublishConnection.d.ts +12 -0
  225. package/dist/src/plugins/websocket/PublishConnection.js +46 -0
  226. package/dist/src/plugins/websocket/PublishConnection.js.map +1 -0
  227. package/dist/src/plugins/websocket/SubscribeConnection.d.ts +13 -0
  228. package/dist/src/plugins/websocket/SubscribeConnection.js +50 -0
  229. package/dist/src/plugins/websocket/SubscribeConnection.js.map +1 -0
  230. package/dist/src/plugins/websocket/WebsocketPlugin.d.ts +19 -0
  231. package/dist/src/plugins/websocket/WebsocketPlugin.js +26 -0
  232. package/dist/src/plugins/websocket/WebsocketPlugin.js.map +1 -0
  233. package/dist/src/plugins/websocket/WebsocketServer.d.ts +16 -0
  234. package/dist/src/plugins/websocket/WebsocketServer.js +132 -0
  235. package/dist/src/plugins/websocket/WebsocketServer.js.map +1 -0
  236. package/dist/src/plugins/websocket/config.schema.json +51 -0
  237. package/package.json +78 -0
  238. package/plugins.md +318 -0
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.inspectTarget = exports.findNodesForTargetGivenFleetState = exports.findTarget = void 0;
7
+ const lodash_1 = require("lodash");
8
+ const protocol_1 = require("@streamr/protocol");
9
+ const ConsistentHashRing_1 = require("./ConsistentHashRing");
10
+ const weightedSample_1 = require("../../helpers/weightedSample");
11
+ const sample_1 = __importDefault(require("lodash/sample"));
12
+ const without_1 = __importDefault(require("lodash/without"));
13
+ function createStreamIDMatcher(streamId) {
14
+ return (streamPart) => {
15
+ return protocol_1.StreamPartIDUtils.getStreamID(streamPart) === streamId;
16
+ };
17
+ }
18
+ function isAnyPartitionOfStreamAssignedToMe(assignments, streamId) {
19
+ return assignments.getMyStreamParts().some(createStreamIDMatcher(streamId));
20
+ }
21
+ function getPartitionsOfStreamAssignedToMe(assignments, streamId) {
22
+ return assignments.getMyStreamParts().filter(createStreamIDMatcher(streamId));
23
+ }
24
+ async function findTarget(myOperatorContractAddress, contractFacade, assignments, logger) {
25
+ // choose sponsorship
26
+ const sponsorships = await contractFacade.getSponsorshipsOfOperator(myOperatorContractAddress);
27
+ const suitableSponsorships = sponsorships
28
+ .filter(({ operatorCount }) => operatorCount >= 2) // exclude sponsorships with only self
29
+ .filter(({ streamId }) => isAnyPartitionOfStreamAssignedToMe(assignments, streamId));
30
+ if (suitableSponsorships.length === 0) {
31
+ logger.info('Skip inspection (no suitable sponsorship)', { totalSponsorships: sponsorships.length });
32
+ return undefined;
33
+ }
34
+ const targetSponsorship = (0, weightedSample_1.weightedSample)(suitableSponsorships, ({ operatorCount }) => operatorCount - 1 // account for self to keep ratios correct
35
+ );
36
+ // choose operator
37
+ const operators = await contractFacade.getOperatorsInSponsorship(targetSponsorship.sponsorshipAddress);
38
+ const targetOperatorAddress = (0, sample_1.default)((0, without_1.default)(operators, myOperatorContractAddress));
39
+ if (targetOperatorAddress === undefined) {
40
+ // Only happens if during the async awaits the other operator(s) were removed from the sponsorship.
41
+ logger.info('Skip inspection (no suitable operator)', { targetSponsorship });
42
+ return undefined;
43
+ }
44
+ // choose stream part
45
+ const streamParts = getPartitionsOfStreamAssignedToMe(assignments, targetSponsorship.streamId);
46
+ const targetStreamPart = (0, sample_1.default)(streamParts);
47
+ if (targetStreamPart === undefined) {
48
+ // Only happens if during the async awaits the stream parts I am assigned to have changed.
49
+ logger.info('Skip inspection (no suitable stream part)', { targetSponsorship, targetOperatorAddress });
50
+ return undefined;
51
+ }
52
+ const flagAlreadyRaised = await contractFacade.hasOpenFlag(targetOperatorAddress, targetSponsorship.sponsorshipAddress);
53
+ if (flagAlreadyRaised) {
54
+ logger.info('Skip inspection (target already has open flag)', { targetSponsorship, targetOperatorAddress });
55
+ return undefined;
56
+ }
57
+ return {
58
+ sponsorshipAddress: targetSponsorship.sponsorshipAddress,
59
+ operatorAddress: targetOperatorAddress,
60
+ streamPart: targetStreamPart
61
+ };
62
+ }
63
+ exports.findTarget = findTarget;
64
+ async function findNodesForTargetGivenFleetState(target, targetOperatorFleetState, getRedundancyFactor, logger) {
65
+ const replicationFactor = await getRedundancyFactor(target.operatorAddress);
66
+ if (replicationFactor === undefined) {
67
+ logger.debug('Encountered misconfigured replication factor');
68
+ return [];
69
+ }
70
+ const consistentHashRing = new ConsistentHashRing_1.ConsistentHashRing(replicationFactor);
71
+ for (const nodeId of targetOperatorFleetState.getNodeIds()) {
72
+ consistentHashRing.add(nodeId);
73
+ }
74
+ const targetNodes = consistentHashRing.get(target.streamPart);
75
+ return targetNodes.map((nodeId) => targetOperatorFleetState.getPeerDescriptor(nodeId));
76
+ }
77
+ exports.findNodesForTargetGivenFleetState = findNodesForTargetGivenFleetState;
78
+ async function inspectTarget({ target, targetPeerDescriptors, streamrClient, abortSignal, logger }) {
79
+ logger.info('Inspecting nodes of operator', {
80
+ targetOperator: target.operatorAddress,
81
+ targetStreamPart: target.streamPart,
82
+ targetNodes: targetPeerDescriptors.map(({ nodeId }) => nodeId),
83
+ targetSponsorship: target.sponsorshipAddress
84
+ });
85
+ // need to subscribe before inspecting, otherwise inspect will instantly return false
86
+ const sub = await streamrClient.subscribe({
87
+ id: protocol_1.StreamPartIDUtils.getStreamID(target.streamPart),
88
+ partition: protocol_1.StreamPartIDUtils.getStreamPartition(target.streamPart),
89
+ raw: true
90
+ });
91
+ try {
92
+ for (const descriptor of (0, lodash_1.shuffle)(targetPeerDescriptors)) {
93
+ // TODO: re-enable when works
94
+ //const result = await streamrClient.inspect(descriptor, target.streamPart)
95
+ const result = true;
96
+ abortSignal.throwIfAborted();
97
+ if (result) {
98
+ logger.info('Inspection done (no issue detected)', {
99
+ targetOperator: target.operatorAddress,
100
+ targetStreamPart: target.streamPart,
101
+ targetNode: descriptor.nodeId,
102
+ targetSponsorship: target.sponsorshipAddress
103
+ });
104
+ return true;
105
+ }
106
+ }
107
+ logger.info('Inspection done (issue detected)', {
108
+ targetOperator: target.operatorAddress,
109
+ targetStreamPart: target.streamPart,
110
+ targetNodes: targetPeerDescriptors.map(({ nodeId }) => nodeId),
111
+ targetSponsorship: target.sponsorshipAddress
112
+ });
113
+ return false;
114
+ }
115
+ finally {
116
+ await sub.unsubscribe();
117
+ }
118
+ }
119
+ exports.inspectTarget = inspectTarget;
120
+ //# sourceMappingURL=inspectionUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inspectionUtils.js","sourceRoot":"","sources":["../../../../src/plugins/operator/inspectionUtils.ts"],"names":[],"mappings":";;;;;;AAAA,mCAAgC;AAGhC,gDAA6E;AAE7E,6DAAyD;AAEzD,iEAA6D;AAC7D,2DAAkC;AAClC,6DAAoC;AAYpC,SAAS,qBAAqB,CAAC,QAAkB;IAC7C,OAAO,CAAC,UAAU,EAAE,EAAE;QAClB,OAAO,4BAAiB,CAAC,WAAW,CAAC,UAAU,CAAC,KAAK,QAAQ,CAAA;IACjE,CAAC,CAAA;AACL,CAAC;AAED,SAAS,kCAAkC,CACvC,WAAkC,EAClC,QAAkB;IAElB,OAAO,WAAW,CAAC,gBAAgB,EAAE,CAAC,IAAI,CAAC,qBAAqB,CAAC,QAAQ,CAAC,CAAC,CAAA;AAC/E,CAAC;AAED,SAAS,iCAAiC,CACtC,WAAkC,EAClC,QAAkB;IAElB,OAAO,WAAW,CAAC,gBAAgB,EAAE,CAAC,MAAM,CAAC,qBAAqB,CAAC,QAAQ,CAAC,CAAC,CAAA;AACjF,CAAC;AAEM,KAAK,UAAU,UAAU,CAC5B,yBAA0C,EAC1C,cAA8B,EAC9B,WAAkC,EAClC,MAAc;IAEd,qBAAqB;IACrB,MAAM,YAAY,GAAG,MAAM,cAAc,CAAC,yBAAyB,CAAC,yBAAyB,CAAC,CAAA;IAC9F,MAAM,oBAAoB,GAAG,YAAY;SACpC,MAAM,CAAC,CAAC,EAAE,aAAa,EAAE,EAAE,EAAE,CAAC,aAAa,IAAI,CAAC,CAAC,CAAE,sCAAsC;SACzF,MAAM,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,kCAAkC,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC,CAAA;IACxF,IAAI,oBAAoB,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACpC,MAAM,CAAC,IAA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ade';
2
+ export declare const maintainOperatorValue: (withdrawLimitSafetyFraction: number, minSponsorshipEarningsInWithdraw: number, maxSponsorshipsInWithdraw: number, contractFacade: ContractFacade) => Promise<void>;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.maintainOperatorValue = void 0;
4
+ const utils_1 = require("@streamr/utils");
5
+ const multiply_1 = require("../../helpers/multiply");
6
+ const logger = new utils_1.Logger(module);
7
+ const maintainOperatorValue = async (withdrawLimitSafetyFraction, minSponsorshipEarningsInWithdraw, maxSponsorshipsInWithdraw, contractFacade) => {
8
+ logger.info('Check whether it is time to withdraw my earnings');
9
+ const { sumDataWei, maxAllowedEarningsDataWei, sponsorshipAddresses } = await contractFacade.getMyEarnings(minSponsorshipEarningsInWithdraw, maxSponsorshipsInWithdraw);
10
+ const triggerWithdrawLimitDataWei = (0, multiply_1.multiply)(maxAllowedEarningsDataWei, 1 - withdrawLimitSafetyFraction);
11
+ logger.trace(` -> is ${sumDataWei} > ${triggerWithdrawLimitDataWei} ?`);
12
+ if (sumDataWei > triggerWithdrawLimitDataWei) {
13
+ logger.info('Withdraw earnings from sponsorships', { sponsorshipAddresses });
14
+ await contractFacade.withdrawMyEarningsFromSponsorships(sponsorshipAddresses);
15
+ }
16
+ else {
17
+ logger.info('Skip withdrawing earnings');
18
+ }
19
+ };
20
+ exports.maintainOperatorValue = maintainOperatorValue;
21
+ //# sourceMappingURL=maintainOperatorValue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"maintainOperatorValue.js","sourceRoot":"","sources":["../../../../src/plugins/operator/maintainOperatorValue.ts"],"names":[],"mappings":";;;AAAA,0CAAuC;AACvC,qDAAiD;AAGjD,MAAM,MAAM,GAAG,IAAI,cAAM,CAAC,MAAM,CAAC,CAAA;AAE1B,MAAM,qBAAqB,GAAG,KAAK,EACtC,2BAAmC,EACnC,gCAAwC,EACxC,yBAAiC,EACjC,cAA8B,EACjB,EAAE;IACf,MAAM,CAAC,IAAI,CAAC,kDAAkD,CAAC,CAAA;IAC/D,MAAM,EAAE,UAAU,EAAE,yBAAyB,EAAE,oBAAoB,EAAE,GAAG,MAAM,cAAc,CAAC,aAAa,CACtG,gCAAgC,EAChC,yBAAyB,CAC5B,CAAA;IACD,MAAM,2BAA2B,GAAG,IAAA,mBAAQ,EAAC,yBAAyB,EAAE,CAAC,GAAG,2BAA2B,CAAC,CAAA;IACxG,MAAM,CAAC,KAAK,CAAC,UAAU,UAAU,MAAM,2BAA2B,IAAI,CAAC,CAAA;IACvE,IAAI,UAAU,GAAG,2BAA2B,EAAE,CAAC;QAC3C,MAAM,CAAC,IAAI,CAAC,qCAAqC,EAAE,EAAE,oBAAoB,EAAE,CAAC,CAAA;QAC5E,MAAM,cAAc,CAAC,kCAAkC,CAAC,oBAAoB,CAAC,CAAA;IACjF,CAAC;SAAM,CAAC;QACJ,MAAM,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAA;IAC5C,CAAC;AACL,CAAC,CAAA;AAnBY,QAAA,qBAAqB,yBAmBjC"}
@@ -0,0 +1,24 @@
1
+ /// <reference types="node" />
2
+ import { EthereumAddress } from '@streamr/utils';
3
+ import { ContractFacade } from './ContractFacade';
4
+ import { StreamrClient } from '@streamr/sdk';
5
+ import { CreateOperatorFleetStateFn } from './OperatorFleetState';
6
+ export interface ReviewProcessOpts {
7
+ sponsorshipAddress: EthereumAddress;
8
+ targetOperator: EthereumAddress;
9
+ partition: number;
10
+ contractFacade: ContractFacade;
11
+ streamrClient: StreamrClient;
12
+ createOperatorFleetState: CreateOperatorFleetStateFn;
13
+ getRedundancyFactor: (operatorContractAddress: EthereumAddress) => Promise<number | undefined>;
14
+ maxSleepTime: number;
15
+ heartbeatTimeoutInMs: number;
16
+ votingPeriod: {
17
+ startTime: number;
18
+ endTime: number;
19
+ };
20
+ inspectionIntervalInMs: number;
21
+ maxInspections: number;
22
+ abortSignal: AbortSignal;
23
+ }
24
+ export declare const reviewSuspectNode: ({ sponsorshipAddress, targetOperator, partition, contractFacade, streamrClient, createOperatorFleetState, getRedundancyFactor, maxSleepTime, heartbeatTimeoutInMs, votingPeriod, inspectionIntervalInMs, maxInspections, abortSignal }: ReviewProcessOpts) => Promise<void>;
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.reviewSuspectNode = void 0;
7
+ const utils_1 = require("@streamr/utils");
8
+ const protocol_1 = require("@streamr/protocol");
9
+ const random_1 = __importDefault(require("lodash/random"));
10
+ const inspectOverTime_1 = require("./inspectOverTime");
11
+ const logger = new utils_1.Logger(module);
12
+ const reviewSuspectNode = async ({ sponsorshipAddress, targetOperator, partition, contractFacade, streamrClient, createOperatorFleetState, getRedundancyFactor, maxSleepTime, heartbeatTimeoutInMs, votingPeriod, inspectionIntervalInMs, maxInspections, abortSignal }) => {
13
+ if (Date.now() + maxSleepTime > votingPeriod.startTime) {
14
+ throw new Error('Max sleep time overlaps with voting period');
15
+ }
16
+ const streamId = await contractFacade.getStreamId(sponsorshipAddress);
17
+ // random sleep time to make sure multiple instances of voters don't all inspect at the same time
18
+ const sleepTimeInMsBeforeFirstInspection = (0, random_1.default)(maxSleepTime);
19
+ const consumeResults = (0, inspectOverTime_1.inspectOverTime)({
20
+ target: {
21
+ sponsorshipAddress: sponsorshipAddress,
22
+ operatorAddress: targetOperator,
23
+ streamPart: (0, protocol_1.toStreamPartID)(streamId, partition),
24
+ },
25
+ streamrClient,
26
+ createOperatorFleetState,
27
+ getRedundancyFactor,
28
+ sleepTimeInMsBeforeFirstInspection,
29
+ heartbeatTimeoutInMs,
30
+ inspectionIntervalInMs,
31
+ maxInspections,
32
+ waitUntilPassOrDone: false,
33
+ abortSignal,
34
+ traceId: (0, utils_1.randomString)(6)
35
+ });
36
+ const timeUntilVoteInMs = ((votingPeriod.startTime + votingPeriod.endTime) / 2) - Date.now();
37
+ logger.debug('Schedule voting on flag', { timeUntilVoteInMs });
38
+ (0, utils_1.setAbortableTimeout)(async () => {
39
+ const results = await consumeResults();
40
+ const kick = results.filter((b) => b).length <= results.length / 2;
41
+ logger.info('Vote on flag', { sponsorshipAddress, targetOperator, kick });
42
+ try {
43
+ await contractFacade.voteOnFlag(sponsorshipAddress, targetOperator, kick);
44
+ }
45
+ catch (err) {
46
+ logger.warn('Encountered error while voting on flag', {
47
+ sponsorshipAddress,
48
+ targetOperator,
49
+ kick,
50
+ reason: err?.message
51
+ });
52
+ }
53
+ }, timeUntilVoteInMs, abortSignal);
54
+ };
55
+ exports.reviewSuspectNode = reviewSuspectNode;
56
+ //# sourceMappingURL=reviewSuspectNode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reviewSuspectNode.js","sourceRoot":"","sources":["../../../../src/plugins/operator/reviewSuspectNode.ts"],"names":[],"mappings":";;;;;;AAAA,0CAA2F;AAI3F,gDAAkD;AAClD,2DAAkC;AAClC,uDAAmD;AAEnD,MAAM,MAAM,GAAG,IAAI,cAAM,CAAC,MAAM,CAAC,CAAA;AAqB1B,MAAM,iBAAiB,GAAG,KAAK,EAAE,EACpC,kBAAkB,EAClB,cAAc,EACd,SAAS,EACT,cAAc,EACd,aAAa,EACb,wBAAwB,EACxB,mBAAmB,EACnB,YAAY,EACZ,oBAAoB,EACpB,YAAY,EACZ,sBAAsB,EACtB,cAAc,EACd,WAAW,EACK,EAAiB,EAAE;IACnC,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,YAAY,GAAG,YAAY,CAAC,SAAS,EAAE,CAAC;QACrD,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAA;IACjE,CAAC;IACD,MAAM,QAAQ,GAAG,MAAM,cAAc,CAAC,WAAW,CAAC,kBAAkB,CAAC,CAAA;IACrE,iGAAiG;IACjG,MAAM,kCAAkC,GAAG,IAAA,gBAAM,EAAC,YAAY,CAAC,CAAA;IA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ACL,CAAC,EAAE,iBAAiB,EAAE,WAAW,CAAC,CAAA;AACtC,CAAC,CAAA;AAxDY,QAAA,iBAAiB,qBAwD7B"}
@@ -0,0 +1,51 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import { EventEmitter } from 'events';
4
+ import { Logger } from '@streamr/utils';
5
+ import { BucketId } from './Bucket';
6
+ export type BatchId = string;
7
+ export type State = string;
8
+ export type DoneCallback = (err?: Error) => void;
9
+ export interface InsertRecord {
10
+ streamId: string;
11
+ partition: number;
12
+ timestamp: number;
13
+ sequenceNo: number;
14
+ publisherId: string;
15
+ msgChainId: string;
16
+ payload: Buffer;
17
+ }
18
+ export declare class Batch extends EventEmitter {
19
+ static states: Readonly<{
20
+ OPENED: "opened";
21
+ LOCKED: "locked";
22
+ PENDING: "pending";
23
+ INSERTED: "inserted";
24
+ }>;
25
+ private id;
26
+ private bucketId;
27
+ logger: Logger;
28
+ private maxSize;
29
+ private maxRecordCount;
30
+ private maxRetries;
31
+ private closeTimeout;
32
+ private timeout;
33
+ createdAt: number;
34
+ records: InsertRecord[];
35
+ size: number;
36
+ retries: number;
37
+ state: State;
38
+ private doneCbs;
39
+ constructor(bucketId: BucketId, maxSize: number, maxRecordCount: number, closeTimeout: number, maxRetries: number);
40
+ reachedMaxRetries(): boolean;
41
+ getId(): string;
42
+ getBucketId(): string;
43
+ lock(): void;
44
+ scheduleInsert(): void;
45
+ done(): void;
46
+ clear(): void;
47
+ push(record: InsertRecord, doneCb?: DoneCallback): void;
48
+ isFull(): boolean;
49
+ private getRecordCount;
50
+ private setState;
51
+ }
@@ -0,0 +1,121 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Batch = void 0;
4
+ const events_1 = require("events");
5
+ const utils_1 = require("@streamr/utils");
6
+ const uuid_1 = require("uuid");
7
+ class Batch extends events_1.EventEmitter {
8
+ // TODO convert to enum and rename to uppercase
9
+ static states = Object.freeze({
10
+ // OPENED => LOCKED => PENDING => INSERTED
11
+ OPENED: 'opened', // opened for adding new messages
12
+ LOCKED: 'locked', // locked for adding new messages, because isFull or timeout
13
+ PENDING: 'pending', // awaiting to be inserted,
14
+ INSERTED: 'inserted'
15
+ });
16
+ id;
17
+ bucketId;
18
+ logger;
19
+ maxSize;
20
+ maxRecordCount;
21
+ maxRetries;
22
+ closeTimeout;
23
+ timeout;
24
+ createdAt;
25
+ records;
26
+ size;
27
+ retries;
28
+ state;
29
+ doneCbs;
30
+ constructor(bucketId, maxSize, maxRecordCount, closeTimeout, maxRetries) {
31
+ if (!bucketId || !bucketId.length) {
32
+ throw new TypeError('bucketId must be not empty string');
33
+ }
34
+ if (maxSize <= 0) {
35
+ throw new TypeError('maxSize must be > 0');
36
+ }
37
+ if (maxRecordCount <= 0) {
38
+ throw new TypeError('maxRecordCount must be > 0');
39
+ }
40
+ if (closeTimeout <= 0) {
41
+ throw new TypeError('closeTimeout must be > 0');
42
+ }
43
+ if (maxRetries <= 0) {
44
+ throw new TypeError('maxRetries must be > 0');
45
+ }
46
+ super();
47
+ this.id = (0, uuid_1.v4)();
48
+ this.bucketId = bucketId;
49
+ this.createdAt = Date.now();
50
+ this.records = [];
51
+ this.size = 0;
52
+ this.retries = 0;
53
+ this.state = Batch.states.OPENED;
54
+ this.doneCbs = [];
55
+ this.logger = new utils_1.Logger(module, { id: this.id });
56
+ this.maxSize = maxSize;
57
+ this.maxRecordCount = maxRecordCount;
58
+ this.maxRetries = maxRetries;
59
+ this.closeTimeout = closeTimeout;
60
+ this.timeout = setTimeout(() => {
61
+ this.logger.trace('lock timeout');
62
+ this.lock();
63
+ }, this.closeTimeout);
64
+ this.logger.trace('init new batch');
65
+ }
66
+ reachedMaxRetries() {
67
+ return this.retries === this.maxRetries;
68
+ }
69
+ getId() {
70
+ return this.id;
71
+ }
72
+ getBucketId() {
73
+ return this.bucketId;
74
+ }
75
+ lock() {
76
+ clearTimeout(this.timeout);
77
+ this.setState(Batch.states.LOCKED);
78
+ }
79
+ scheduleInsert() {
80
+ clearTimeout(this.timeout);
81
+ this.logger.trace('scheduleRetry', {
82
+ retries: this.retries
83
+ });
84
+ this.timeout = setTimeout(() => {
85
+ if (this.retries < this.maxRetries) {
86
+ this.retries += 1;
87
+ }
88
+ this.setState(Batch.states.PENDING);
89
+ }, this.closeTimeout * this.retries);
90
+ }
91
+ done() {
92
+ this.doneCbs.forEach((doneCb) => doneCb());
93
+ this.doneCbs = [];
94
+ }
95
+ clear() {
96
+ this.logger.trace('clear');
97
+ clearTimeout(this.timeout);
98
+ this.records = [];
99
+ this.setState(Batch.states.INSERTED);
100
+ }
101
+ push(record, doneCb) {
102
+ this.records.push(record);
103
+ this.size += record.payload.length;
104
+ if (doneCb !== undefined) {
105
+ this.doneCbs.push(doneCb);
106
+ }
107
+ }
108
+ isFull() {
109
+ return this.size >= this.maxSize || this.getRecordCount() >= this.maxRecordCount;
110
+ }
111
+ getRecordCount() {
112
+ return this.records.length;
113
+ }
114
+ setState(state) {
115
+ this.state = state;
116
+ this.logger.trace('setState', { state });
117
+ this.emit(this.state, this.getBucketId(), this.getId(), this.state, this.size, this.getRecordCount());
118
+ }
119
+ }
120
+ exports.Batch = Batch;
121
+ //# sourceMappingURL=Batch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Batch.js","sourceRoot":"","sources":["../../../../src/plugins/storage/Batch.ts"],"names":[],"mappings":";;;AAAA,mCAAqC;AACrC,0CAAuC;AACvC,+BAAmC;AAiBnC,MAAa,KAAM,SAAQ,qBAAY;IAEnC,+CAA+C;IAC/C,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAC1B,0CAA0C;QAC1C,MAAM,EAAE,QAAQ,EAAE,iCAAiC;QACnD,MAAM,EAAE,QAAQ,EAAE,4DAA4D;QAC9E,OAAO,EAAE,SAAS,EAAE,2BAA2B;QAC/C,QAAQ,EAAE,UAAU;KACvB,CAAC,CAAA;IAEM,EAAE,CAAS;IACX,QAAQ,CAAU;IAC1B,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E,EAAE,KAAK,EAAE,CAAC,CAAA;QACxC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,WAAW,EAAE,EAAE,IAAI,CAAC,KAAK,EAAE,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,cAAc,EAAE,CAAC,CAAA;IACzG,CAAC;;AAxIL,sBAyIC"}
@@ -0,0 +1,27 @@
1
+ /// <reference types="node" />
2
+ import { Client } from 'cassandra-driver';
3
+ import { EventEmitter } from 'events';
4
+ import { Logger } from '@streamr/utils';
5
+ import { Batch, BatchId, DoneCallback, InsertRecord } from './Batch';
6
+ import { BucketId } from './Bucket';
7
+ export interface BatchManagerOptions {
8
+ useTtl: boolean;
9
+ logErrors: boolean;
10
+ batchMaxSize: number;
11
+ batchMaxRecordCount: number;
12
+ batchCloseTimeout: number;
13
+ batchMaxRetries: number;
14
+ }
15
+ export declare class BatchManager extends EventEmitter {
16
+ opts: BatchManagerOptions;
17
+ batches: Record<BucketId, Batch>;
18
+ pendingBatches: Record<BatchId, Batch>;
19
+ cassandraClient: Client;
20
+ insertStatement: string;
21
+ logger: Logger;
22
+ constructor(cassandraClient: Client, opts?: Partial<BatchManagerOptions>);
23
+ store(bucketId: BucketId, record: InsertRecord, doneCb?: DoneCallback): void;
24
+ stop(): void;
25
+ private moveFullBatch;
26
+ private insert;
27
+ }
@@ -0,0 +1,117 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BatchManager = void 0;
4
+ const events_1 = require("events");
5
+ const utils_1 = require("@streamr/utils");
6
+ const Batch_1 = require("./Batch");
7
+ const utils_2 = require("@streamr/utils");
8
+ const INSERT_STATEMENT = 'INSERT INTO stream_data '
9
+ + '(stream_id, partition, bucket_id, ts, sequence_no, publisher_id, msg_chain_id, payload) '
10
+ + 'VALUES (?, ?, ?, ?, ?, ?, ?, ?)';
11
+ const INSERT_STATEMENT_WITH_TTL = 'INSERT INTO stream_data '
12
+ + '(stream_id, partition, bucket_id, ts, sequence_no, publisher_id, msg_chain_id, payload) '
13
+ + 'VALUES (?, ?, ?, ?, ?, ?, ?, ?) USING TTL 259200'; // 3 days
14
+ let ID = 0;
15
+ class BatchManager extends events_1.EventEmitter {
16
+ opts;
17
+ batches;
18
+ pendingBatches;
19
+ cassandraClient;
20
+ insertStatement;
21
+ logger;
22
+ constructor(cassandraClient, opts = {}) {
23
+ super();
24
+ ID += 1;
25
+ this.logger = new utils_1.Logger(module, { id: `${ID}` });
26
+ const defaultOptions = {
27
+ useTtl: false,
28
+ logErrors: false,
29
+ batchMaxSize: 8000 * 300,
30
+ batchMaxRecordCount: 8000,
31
+ batchCloseTimeout: 1000,
32
+ batchMaxRetries: 1000 // in total max ~16 minutes timeout
33
+ };
34
+ this.opts = (0, utils_2.merge)(defaultOptions, opts);
35
+ // bucketId => batch
36
+ this.batches = Object.create(null);
37
+ // batchId => batch
38
+ this.pendingBatches = Object.create(null);
39
+ this.cassandraClient = cassandraClient;
40
+ this.insertStatement = this.opts.useTtl ? INSERT_STATEMENT_WITH_TTL : INSERT_STATEMENT;
41
+ }
42
+ store(bucketId, record, doneCb) {
43
+ const batch = this.batches[bucketId];
44
+ if (batch && batch.isFull()) {
45
+ batch.lock();
46
+ }
47
+ if (this.batches[bucketId] === undefined) {
48
+ this.logger.trace('Create new batch');
49
+ const newBatch = new Batch_1.Batch(bucketId, this.opts.batchMaxSize, this.opts.batchMaxRecordCount, this.opts.batchCloseTimeout, this.opts.batchMaxRetries);
50
+ newBatch.on('locked', () => this.moveFullBatch(bucketId, newBatch));
51
+ newBatch.on('pending', () => this.insert(newBatch.getId()));
52
+ this.batches[bucketId] = newBatch;
53
+ }
54
+ this.batches[bucketId].push(record, doneCb);
55
+ }
56
+ stop() {
57
+ const { batches, pendingBatches } = this;
58
+ this.batches = Object.create(null);
59
+ this.pendingBatches = Object.create(null);
60
+ Object.values(batches).forEach((batch) => batch.clear());
61
+ Object.values(pendingBatches).forEach((batch) => batch.clear());
62
+ }
63
+ moveFullBatch(bucketId, batch) {
64
+ const batchId = batch.getId();
65
+ this.pendingBatches[batchId] = batch;
66
+ batch.scheduleInsert();
67
+ delete this.batches[bucketId];
68
+ }
69
+ async insert(batchId) {
70
+ const batch = this.pendingBatches[batchId];
71
+ try {
72
+ const queries = batch.records.map((record) => {
73
+ return {
74
+ query: this.insertStatement,
75
+ params: [
76
+ record.streamId,
77
+ record.partition,
78
+ batch.getBucketId(),
79
+ record.timestamp,
80
+ record.sequenceNo,
81
+ record.publisherId,
82
+ record.msgChainId,
83
+ record.payload,
84
+ ]
85
+ };
86
+ });
87
+ await this.cassandraClient.batch(queries, {
88
+ prepare: true
89
+ });
90
+ this.logger.trace('Insert batch', { batchId: batch.getId() });
91
+ batch.done();
92
+ batch.clear();
93
+ delete this.pendingBatches[batch.getId()];
94
+ }
95
+ catch (err) {
96
+ if (this.opts.logErrors) {
97
+ this.logger.error('Failed to insert batch', { batchId, err });
98
+ }
99
+ // stop if reached max retries
100
+ // TODO: This probably belongs in Batch
101
+ if (batch.reachedMaxRetries()) {
102
+ if (this.opts.logErrors) {
103
+ this.logger.error('Drop batch (max retries reached)', {
104
+ batchId: batch.getId(),
105
+ retries: batch.retries
106
+ });
107
+ }
108
+ batch.clear();
109
+ delete this.pendingBatches[batch.getId()];
110
+ return;
111
+ }
112
+ batch.scheduleInsert();
113
+ }
114
+ }
115
+ }
116
+ exports.BatchManager = BatchManager;
117
+ //# sourceMappingURL=BatchManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BatchManager.js","sourceRoot":"","sources":["../../../../src/plugins/storage/BatchManager.ts"],"names":[],"mappings":";;;AACA,mCAAqC;AACrC,0CAAuC;AACvC,mCAAoE;AAEpE,0CAAsC;AAEtC,MAAM,gBAAgB,GAAG,0BAA0B;MAC7C,0FAA0F;MAC1F,iCAAiC,CAAA;AAEvC,MAAM,yBAAyB,GAAG,0BAA0B;MACtD,0FAA0F;M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A;QAC7C,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACX,IAAI,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;gBACtB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,wBAAwB,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,CAAA;YACjE,CAAC;YAED,8BAA8B;YAC9B,uCAAuC;YACvC,IAAI,KAAK,CAAC,iBAAiB,EAAE,EAAE,CAAC;gBAC5B,IAAI,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;oBACtB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,kCAAkC,EAAE;wBAClD,OAAO,EAAE,KAAK,CAAC,KAAK,EAAE;wBACtB,OAAO,EAAE,KAAK,CAAC,OAAO;qBACzB,CAAC,CAAA;gBACN,CAAC;gBACD,KAAK,CAAC,KAAK,EAAE,CAAA;gBACb,OAAO,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAA;gBACzC,OAAM;YACV,CAAC;YAED,KAAK,CAAC,cAAc,EAAE,CAAA;QAC1B,CAAC;IACL,CAAC;CACJ;AA/HD,oCA+HC"}
@@ -0,0 +1,23 @@
1
+ export type BucketId = string;
2
+ export declare class Bucket {
3
+ id: BucketId;
4
+ streamId: string;
5
+ partition: number;
6
+ size: number;
7
+ records: number;
8
+ dateCreate: Date;
9
+ private maxSize;
10
+ private maxRecordCount;
11
+ private keepAliveSeconds;
12
+ ttl: Date;
13
+ private stored;
14
+ constructor(id: BucketId, streamId: string, partition: number, size: number, records: number, dateCreate: Date, maxSize: number, maxRecordCount: number, keepAliveSeconds: number);
15
+ isStored(): boolean;
16
+ setStored(): void;
17
+ private checkSize;
18
+ isAlmostFull(percentDeduction?: number): boolean;
19
+ getId(): string;
20
+ incrementBucket(size: number): void;
21
+ private updateTTL;
22
+ isAlive(): boolean;
23
+ }