@convex-dev/sharded-counter 0.1.3 → 0.1.5
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/README.md +136 -7
- package/dist/commonjs/client/index.d.ts +96 -13
- package/dist/commonjs/client/index.d.ts.map +1 -1
- package/dist/commonjs/client/index.js +108 -5
- package/dist/commonjs/client/index.js.map +1 -1
- package/dist/commonjs/component/_generated/api.d.ts.map +1 -1
- package/dist/commonjs/component/_generated/api.js +0 -2
- package/dist/commonjs/component/_generated/api.js.map +1 -1
- package/dist/commonjs/component/_generated/server.d.ts.map +1 -1
- package/dist/commonjs/component/_generated/server.js +0 -2
- package/dist/commonjs/component/_generated/server.js.map +1 -1
- package/dist/commonjs/component/public.d.ts +14 -1
- package/dist/commonjs/component/public.d.ts.map +1 -1
- package/dist/commonjs/component/public.js +75 -2
- package/dist/commonjs/component/public.js.map +1 -1
- package/dist/esm/client/index.d.ts +96 -13
- package/dist/esm/client/index.d.ts.map +1 -1
- package/dist/esm/client/index.js +108 -5
- package/dist/esm/client/index.js.map +1 -1
- package/dist/esm/component/_generated/api.d.ts.map +1 -1
- package/dist/esm/component/_generated/api.js +0 -2
- package/dist/esm/component/_generated/api.js.map +1 -1
- package/dist/esm/component/_generated/server.d.ts.map +1 -1
- package/dist/esm/component/_generated/server.js +0 -2
- package/dist/esm/component/_generated/server.js.map +1 -1
- package/dist/esm/component/public.d.ts +14 -1
- package/dist/esm/component/public.d.ts.map +1 -1
- package/dist/esm/component/public.js +75 -2
- package/dist/esm/component/public.js.map +1 -1
- package/package.json +2 -2
- package/src/client/index.ts +174 -17
- package/src/component/_generated/api.d.ts +15 -6
- package/src/component/_generated/api.js +0 -4
- package/src/component/_generated/dataModel.d.ts +0 -4
- package/src/component/_generated/server.d.ts +0 -4
- package/src/component/_generated/server.js +0 -4
- package/src/component/counter.test.ts +48 -6
- package/src/component/public.ts +86 -2
package/README.md
CHANGED
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://badge.fury.io/js/@convex-dev%2Fsharded-counter)
|
|
4
4
|
|
|
5
|
-
**Note: Convex Components are currently in beta.**
|
|
6
|
-
|
|
7
5
|
<!-- START: Include on https://convex.dev/components -->
|
|
8
6
|
|
|
9
7
|
This component adds counters to Convex. It acts as a key-value store from
|
|
10
8
|
string to number, with sharding to increase throughput when updating values.
|
|
11
9
|
|
|
12
10
|
Since it's built on Convex, everything is automatically consistent, reactive,
|
|
13
|
-
and cached.
|
|
11
|
+
and cached. Since it's built with [Components](https://convex.dev/components),
|
|
12
|
+
the operations are isolated and increment/decrement are atomic even if run in
|
|
13
|
+
parallel.
|
|
14
14
|
|
|
15
15
|
For example, if you want to display
|
|
16
16
|
[one million checkboxes](https://en.wikipedia.org/wiki/One_Million_Checkboxes)
|
|
@@ -95,14 +95,18 @@ Once you have a `ShardedCounter`, there are a few methods you can use to update
|
|
|
95
95
|
the counter for a key in a mutation or action.
|
|
96
96
|
|
|
97
97
|
```ts
|
|
98
|
-
await counter.add(ctx, "checkboxes"); // increment
|
|
99
|
-
await counter.
|
|
98
|
+
await counter.add(ctx, "checkboxes", 5); // increment by 5
|
|
99
|
+
await counter.inc(ctx, "checkboxes"); // increment by 1
|
|
100
|
+
await counter.subtract(ctx, "checkboxes", 5); // decrement by 5
|
|
101
|
+
await counter.dec(ctx, "checkboxes"); // decrement by 1
|
|
102
|
+
await counter.reset(ctx, "checkboxes"); // reset to 0
|
|
100
103
|
|
|
101
104
|
const numCheckboxes = counter.for("checkboxes");
|
|
102
105
|
await numCheckboxes.inc(ctx); // increment
|
|
103
106
|
await numCheckboxes.dec(ctx); // decrement
|
|
104
107
|
await numCheckboxes.add(ctx, 5); // add 5
|
|
105
108
|
await numCheckboxes.subtract(ctx, 5); // subtract 5
|
|
109
|
+
await numCheckboxes.reset(ctx); // reset to 0
|
|
106
110
|
```
|
|
107
111
|
|
|
108
112
|
And you can read the counter's value in a query, mutation, or action.
|
|
@@ -141,7 +145,7 @@ Or by setting a default that applies to all keys not specified in `shards`:
|
|
|
141
145
|
```ts
|
|
142
146
|
const counter = new ShardedCounter(components.shardedCounter, {
|
|
143
147
|
shards: { checkboxes: 100 },
|
|
144
|
-
defaultShards:
|
|
148
|
+
defaultShards: 8,
|
|
145
149
|
});
|
|
146
150
|
```
|
|
147
151
|
|
|
@@ -158,9 +162,118 @@ const friendCounts = new ShardedCounter<Record<Id<"users">, number>>(
|
|
|
158
162
|
);
|
|
159
163
|
|
|
160
164
|
// Decrement a user's friend count by 1
|
|
161
|
-
await friendsCount.
|
|
165
|
+
await friendsCount.dec(ctx, userId);
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## Reduce contention on reads
|
|
169
|
+
|
|
170
|
+
Reading the count with `counter.count(ctx, "checkboxes")` reads from all shards
|
|
171
|
+
to get an accurate count. This takes a read dependency on all shard documents.
|
|
172
|
+
|
|
173
|
+
- In a query subscription, that means any change to the counter causes the query
|
|
174
|
+
to rerun.
|
|
175
|
+
- In a mutation, that means any modification to the counter causes an
|
|
176
|
+
[OCC](https://docs.convex.dev/error#1) conflict.
|
|
177
|
+
|
|
178
|
+
You can reduce contention by estimating the count: read from a smaller number
|
|
179
|
+
of shards and extrapolate based on the total number of shards.
|
|
180
|
+
|
|
181
|
+
```ts
|
|
182
|
+
const estimatedCheckboxCount = await counter.estimateCount(ctx, "checkboxes");
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
By default, this reads from a single random shard and multiplies by the total
|
|
186
|
+
number of shards to form an estimate. You can improve the estimate by reading
|
|
187
|
+
from more shards, at the cost of more contention:
|
|
188
|
+
|
|
189
|
+
```ts
|
|
190
|
+
const estimateFromThree = await counter.estimateCount(ctx, "checkboxes", 3);
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
If the counter was accumulated from many
|
|
194
|
+
small `counter.inc` and `counter.dec` calls, then they should be uniformly
|
|
195
|
+
distributed across the shards, so estimated counts will be accurate.
|
|
196
|
+
|
|
197
|
+
In some cases the counter will not be evenly distributed:
|
|
198
|
+
|
|
199
|
+
- If the counter was accumulated from few operations
|
|
200
|
+
- If some operations were `counter.add`s or `counter.subtract`s with large
|
|
201
|
+
values, because each operation only changes a single shard
|
|
202
|
+
- If the number of shards changed
|
|
203
|
+
|
|
204
|
+
In these cases, the count might not be evenly distributed across the shards.
|
|
205
|
+
To repair such cases, you can call:
|
|
206
|
+
|
|
207
|
+
```ts
|
|
208
|
+
await counter.rebalance(ctx, "checkboxes");
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
Which will even out the count across shards.
|
|
212
|
+
|
|
213
|
+
You may change the number of shards for a key, by changing the second argument
|
|
214
|
+
to the `ShardedCounter` constructor. If you decrease the number of shards,
|
|
215
|
+
you will be left with extra shards that won't be written to but are still
|
|
216
|
+
read when computing `count`.
|
|
217
|
+
In this case, you should call `counter.rebalance` to delete
|
|
218
|
+
the extraneous shards.
|
|
219
|
+
|
|
220
|
+
NOTE: `counter.rebalance` reads and writes all shards, so it could cause
|
|
221
|
+
more OCCs, and it's recommended you call it sparingly, from the Convex dashboard
|
|
222
|
+
or from an infrequent cron.
|
|
223
|
+
|
|
224
|
+
NOTE: counts are floats, and floating point arithmetic isn't infinitely
|
|
225
|
+
precise. Even if you always add and subtract integers, you may get a fractional
|
|
226
|
+
counts, especially if you use `estimateCount` or `rebalance`.
|
|
227
|
+
Values distributed across shards may be added in different combinations, and
|
|
228
|
+
[floating point arithmetic isn't associative](https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html).
|
|
229
|
+
You can use `Math.round` to ensure your final count is an integer, if
|
|
230
|
+
desired.
|
|
231
|
+
|
|
232
|
+
## Counting documents in a table
|
|
233
|
+
|
|
234
|
+
Often you want to use a sharded counter to track how many documents are in a
|
|
235
|
+
table.
|
|
236
|
+
|
|
237
|
+
> If you want more than just a count, take a look at the
|
|
238
|
+
> [Aggregate component](https://www.npmjs.com/package/@convex-dev/aggregate).
|
|
239
|
+
|
|
240
|
+
There are three ways to go about keeping a count in sync with a table:
|
|
241
|
+
|
|
242
|
+
1. Be careful to always update the aggregate in any mutation that inserts or
|
|
243
|
+
deletes from the table.
|
|
244
|
+
2. \[Recommended\] Place all writes to a table in separate TypeScript functions,
|
|
245
|
+
and always call these functions from mutations instead of writing to the db
|
|
246
|
+
directly. This method is recommended, because it encapsulates the logic for
|
|
247
|
+
updating a table, while still keeping all operations explicit. For example,
|
|
248
|
+
|
|
249
|
+
```ts
|
|
250
|
+
// Example of a mutation that calls `insertUser`.
|
|
251
|
+
export const insertPair = mutation(async (ctx) => {
|
|
252
|
+
...
|
|
253
|
+
await insertUser(ctx, user1);
|
|
254
|
+
await insertUser(ctx, user2);
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
// All inserts to the "users" table go through this function.
|
|
258
|
+
async function insertUser(ctx, user) {
|
|
259
|
+
await ctx.db.insert("users", user);
|
|
260
|
+
await counter.inc(ctx, "users");
|
|
261
|
+
}
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
3. Register a [Trigger](https://www.npmjs.com/package/convex-helpers#triggers),
|
|
265
|
+
which automatically runs code when a mutation changes the
|
|
266
|
+
data in a table.
|
|
267
|
+
|
|
268
|
+
```ts
|
|
269
|
+
// Triggers hook up writes to the table to the ShardedCounter.
|
|
270
|
+
const triggers = new Triggers<DataModel>();
|
|
271
|
+
triggers.register("mytable", counter.trigger("mycounter"));
|
|
272
|
+
export const mutation = customMutation(rawMutation, customCtx(triggers.wrapDB));
|
|
162
273
|
```
|
|
163
274
|
|
|
275
|
+
The [insertUserWithTrigger](example/convex/example.ts) mutation uses a trigger.
|
|
276
|
+
|
|
164
277
|
## Backfilling an existing count
|
|
165
278
|
|
|
166
279
|
If you want to count items like documents in a table, you may already have
|
|
@@ -174,6 +287,22 @@ the value and update the counter, if there aren't in-flight requests.
|
|
|
174
287
|
The tricky part is handling requests while doing the calculation: making sure to
|
|
175
288
|
merge active updates to counts with old values that you want to backfill.
|
|
176
289
|
|
|
290
|
+
### Simple backfill: if table is append-only
|
|
291
|
+
|
|
292
|
+
See example code at the bottom of
|
|
293
|
+
[example/convex/example.ts](example/convex/example.ts).
|
|
294
|
+
|
|
295
|
+
Walkthrough of steps:
|
|
296
|
+
|
|
297
|
+
1. Change live writes to update the counter. In the example, you would be
|
|
298
|
+
changing `insertUserBeforeBackfill` to be implemented as
|
|
299
|
+
`insertUserAfterBackfill`.
|
|
300
|
+
2. Write a backfill that counts documents that were created before the code from
|
|
301
|
+
(1) deployed. In the example, this would be `backfillOldUsers`.
|
|
302
|
+
3. Run `backfillOldUsers` from the dashboard.
|
|
303
|
+
|
|
304
|
+
### Complex backfill: if documents may be deleted
|
|
305
|
+
|
|
177
306
|
See example code at the bottom of
|
|
178
307
|
[example/convex/example.ts](example/convex/example.ts).
|
|
179
308
|
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import { Expand, FunctionReference, GenericDataModel, GenericMutationCtx, GenericQueryCtx } from "convex/server";
|
|
1
|
+
import { DocumentByName, Expand, FunctionReference, GenericDataModel, GenericMutationCtx, GenericQueryCtx, TableNamesInDataModel } from "convex/server";
|
|
2
2
|
import { GenericId } from "convex/values";
|
|
3
3
|
import { api } from "../component/_generated/api";
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* A sharded counter is a map from string -> counter, where each counter can
|
|
6
|
+
* be incremented or decremented atomically.
|
|
7
|
+
*/
|
|
8
|
+
export declare class ShardedCounter<ShardsKey extends string> {
|
|
5
9
|
private component;
|
|
6
|
-
private options?;
|
|
7
10
|
/**
|
|
8
11
|
* A sharded counter is a map from string -> counter, where each counter can
|
|
9
12
|
* be incremented or decremented.
|
|
@@ -20,9 +23,11 @@ export declare class ShardedCounter<Shards extends Record<string, number>> {
|
|
|
20
23
|
* keys not in `options.shards`.
|
|
21
24
|
*/
|
|
22
25
|
constructor(component: UseApi<typeof api>, options?: {
|
|
23
|
-
shards?:
|
|
24
|
-
defaultShards?: number
|
|
25
|
-
}
|
|
26
|
+
shards?: Partial<Record<ShardsKey, number>>;
|
|
27
|
+
defaultShards?: number;
|
|
28
|
+
});
|
|
29
|
+
private shardsForKey;
|
|
30
|
+
private stickyShard;
|
|
26
31
|
/**
|
|
27
32
|
* Increase the counter for key `name` by `count`.
|
|
28
33
|
* If `count` is negative, the counter will decrease.
|
|
@@ -30,14 +35,57 @@ export declare class ShardedCounter<Shards extends Record<string, number>> {
|
|
|
30
35
|
* @param name The key to update the counter for.
|
|
31
36
|
* @param count The amount to increment the counter by. Defaults to 1.
|
|
32
37
|
*/
|
|
33
|
-
add<Name extends
|
|
38
|
+
add<Name extends ShardsKey>(ctx: RunMutationCtx, name: Name, count?: number): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Decrease the counter for key `name` by `count`.
|
|
41
|
+
*/
|
|
42
|
+
subtract<Name extends ShardsKey>(ctx: RunMutationCtx, name: Name, count?: number): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* Increment the counter for key `name` by 1.
|
|
45
|
+
*/
|
|
46
|
+
inc<Name extends ShardsKey>(ctx: RunMutationCtx, name: Name): Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
* Decrement the counter for key `name` by 1.
|
|
49
|
+
*/
|
|
50
|
+
dec<Name extends ShardsKey>(ctx: RunMutationCtx, name: Name): Promise<void>;
|
|
34
51
|
/**
|
|
35
52
|
* Gets the counter for key `name`.
|
|
36
53
|
*
|
|
37
54
|
* NOTE: this reads from all shards. If used in a mutation, it will contend
|
|
38
55
|
* with all mutations that update the counter for this key.
|
|
39
56
|
*/
|
|
40
|
-
count<Name extends
|
|
57
|
+
count<Name extends ShardsKey>(ctx: RunQueryCtx, name: Name): Promise<number>;
|
|
58
|
+
/**
|
|
59
|
+
* Redistribute counts evenly across the counter's shards.
|
|
60
|
+
*
|
|
61
|
+
* If there were more shards for this counter at some point, those shards
|
|
62
|
+
* will be removed.
|
|
63
|
+
*
|
|
64
|
+
* If there were fewer shards for this counter, or if the random distribution
|
|
65
|
+
* of counts is uneven, the counts will be redistributed evenly.
|
|
66
|
+
*
|
|
67
|
+
* This operation reads and writes all shards, so it can cause contention if
|
|
68
|
+
* called too often.
|
|
69
|
+
*/
|
|
70
|
+
rebalance<Name extends ShardsKey>(ctx: RunMutationCtx, name: Name): Promise<void>;
|
|
71
|
+
/**
|
|
72
|
+
* Clear the counter for key `name`.
|
|
73
|
+
*
|
|
74
|
+
* @param name The key to clear the counter for.
|
|
75
|
+
*/
|
|
76
|
+
reset<Name extends ShardsKey>(ctx: RunMutationCtx, name: Name): Promise<void>;
|
|
77
|
+
/**
|
|
78
|
+
* Estimate the count of a counter by only reading from a subset of shards,
|
|
79
|
+
* and extrapolating the total count.
|
|
80
|
+
*
|
|
81
|
+
* After a `rebalance`, or if there were a lot of data points to yield a
|
|
82
|
+
* random distribution across shards, this should be a good approximation of
|
|
83
|
+
* the total count. If there are few data points, which are not evenly
|
|
84
|
+
* distributed across shards, this will be a poor approximation.
|
|
85
|
+
*
|
|
86
|
+
* Use this to reduce contention when reading the counter.
|
|
87
|
+
*/
|
|
88
|
+
estimateCount<Name extends ShardsKey>(ctx: RunQueryCtx, name: Name, readFromShards?: number): Promise<number>;
|
|
41
89
|
/**
|
|
42
90
|
* Returns an object with methods to update and query the counter for key
|
|
43
91
|
* `name`. For fixed keys, you can call `counter.for("<key>")` to get methods
|
|
@@ -53,23 +101,23 @@ export declare class ShardedCounter<Shards extends Record<string, number>> {
|
|
|
53
101
|
* });
|
|
54
102
|
* ```
|
|
55
103
|
*/
|
|
56
|
-
for<Name extends
|
|
104
|
+
for<Name extends ShardsKey>(name: Name): {
|
|
57
105
|
/**
|
|
58
106
|
* Add `count` to the counter.
|
|
59
107
|
*/
|
|
60
|
-
add: (ctx: RunMutationCtx, count?: number) => Promise<
|
|
108
|
+
add: (ctx: RunMutationCtx, count?: number) => Promise<void>;
|
|
61
109
|
/**
|
|
62
110
|
* Subtract `count` from the counter.
|
|
63
111
|
*/
|
|
64
|
-
subtract: (ctx: RunMutationCtx, count?: number) => Promise<
|
|
112
|
+
subtract: (ctx: RunMutationCtx, count?: number) => Promise<void>;
|
|
65
113
|
/**
|
|
66
114
|
* Increment the counter by 1.
|
|
67
115
|
*/
|
|
68
|
-
inc: (ctx: RunMutationCtx) => Promise<
|
|
116
|
+
inc: (ctx: RunMutationCtx) => Promise<void>;
|
|
69
117
|
/**
|
|
70
118
|
* Decrement the counter by 1.
|
|
71
119
|
*/
|
|
72
|
-
dec: (ctx: RunMutationCtx) => Promise<
|
|
120
|
+
dec: (ctx: RunMutationCtx) => Promise<void>;
|
|
73
121
|
/**
|
|
74
122
|
* Get the current value of the counter.
|
|
75
123
|
*
|
|
@@ -77,8 +125,43 @@ export declare class ShardedCounter<Shards extends Record<string, number>> {
|
|
|
77
125
|
* contend with all mutations that update the counter for this key.
|
|
78
126
|
*/
|
|
79
127
|
count: (ctx: RunQueryCtx) => Promise<number>;
|
|
128
|
+
/**
|
|
129
|
+
* Reset the counter for this key.
|
|
130
|
+
*/
|
|
131
|
+
reset: (ctx: RunMutationCtx) => Promise<void>;
|
|
132
|
+
/**
|
|
133
|
+
* Redistribute counts evenly across the counter's shards.
|
|
134
|
+
*
|
|
135
|
+
* This operation reads and writes all shards, so it can cause contention
|
|
136
|
+
* if called too often.
|
|
137
|
+
*/
|
|
138
|
+
rebalance: (ctx: RunMutationCtx) => Promise<void>;
|
|
139
|
+
/**
|
|
140
|
+
* Estimate the counter by only reading from a subset of shards,
|
|
141
|
+
* and extrapolating the total count.
|
|
142
|
+
*
|
|
143
|
+
* Use this to reduce contention when reading the counter.
|
|
144
|
+
*/
|
|
145
|
+
estimateCount: (ctx: RunQueryCtx, readFromShards?: number) => Promise<number>;
|
|
80
146
|
};
|
|
147
|
+
trigger<Ctx extends RunMutationCtx, Name extends ShardsKey>(name: Name): Trigger<Ctx, GenericDataModel, TableNamesInDataModel<GenericDataModel>>;
|
|
81
148
|
}
|
|
149
|
+
export type Trigger<Ctx, DataModel extends GenericDataModel, TableName extends TableNamesInDataModel<DataModel>> = (ctx: Ctx, change: Change<DataModel, TableName>) => Promise<void>;
|
|
150
|
+
export type Change<DataModel extends GenericDataModel, TableName extends TableNamesInDataModel<DataModel>> = {
|
|
151
|
+
id: GenericId<TableName>;
|
|
152
|
+
} & ({
|
|
153
|
+
operation: "insert";
|
|
154
|
+
oldDoc: null;
|
|
155
|
+
newDoc: DocumentByName<DataModel, TableName>;
|
|
156
|
+
} | {
|
|
157
|
+
operation: "update";
|
|
158
|
+
oldDoc: DocumentByName<DataModel, TableName>;
|
|
159
|
+
newDoc: DocumentByName<DataModel, TableName>;
|
|
160
|
+
} | {
|
|
161
|
+
operation: "delete";
|
|
162
|
+
oldDoc: DocumentByName<DataModel, TableName>;
|
|
163
|
+
newDoc: null;
|
|
164
|
+
});
|
|
82
165
|
type RunQueryCtx = {
|
|
83
166
|
runQuery: GenericQueryCtx<GenericDataModel>["runQuery"];
|
|
84
167
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,iBAAiB,EACjB,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,MAAM,EACN,iBAAiB,EACjB,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EACf,qBAAqB,EACtB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,GAAG,EAAE,MAAM,6BAA6B,CAAC;AAElD;;;GAGG;AACH,qBAAa,cAAc,CAAC,SAAS,SAAS,MAAM;IAiBhD,OAAO,CAAC,SAAS;IAhBnB;;;;;;;;;;;;;;OAcG;gBAEO,SAAS,EAAE,MAAM,CAAC,OAAO,GAAG,CAAC,EACrC,OAAO,CAAC,E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AAE,eAAe,CAAC,gBAAgB,CAAC,CAAC,UAAU,CAAC,CAAC;CACzD,CAAC;AACF,KAAK,cAAc,GAAG;IACpB,WAAW,EAAE,kBAAkB,CAAC,gBAAgB,CAAC,CAAC,aAAa,CAAC,CAAC;CAClE,CAAC;AAEF,MAAM,MAAM,SAAS,CAAC,CAAC,IACrB,CAAC,SAAS,SAAS,CAAC,MAAM,EAAE,CAAC,GACzB,MAAM,GACN,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,GACnB,SAAS,CAAC,CAAC,CAAC,EAAE,GACd,CAAC,SAAS,MAAM,GACd;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAAE,GACnC,CAAC,CAAC;AAEZ,MAAM,MAAM,MAAM,CAAC,GAAG,IAAI,MAAM,CAAC;KAC9B,GAAG,IAAI,MAAM,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,SAAS,iBAAiB,CACpD,MAAM,KAAK,EACX,QAAQ,EACR,MAAM,KAAK,EACX,MAAM,WAAW,EACjB,MAAM,cAAc,CACrB,GACG,iBAAiB,CACf,KAAK,EACL,UAAU,EACV,SAAS,CAAC,KAAK,CAAC,EAChB,SAAS,CAAC,WAAW,CAAC,EACtB,cAAc,CACf,GACD,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;CACrB,CAAC,CAAC"}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A sharded counter is a map from string -> counter, where each counter can
|
|
3
|
+
* be incremented or decremented atomically.
|
|
4
|
+
*/
|
|
1
5
|
export class ShardedCounter {
|
|
2
6
|
component;
|
|
3
|
-
options;
|
|
4
7
|
/**
|
|
5
8
|
* A sharded counter is a map from string -> counter, where each counter can
|
|
6
9
|
* be incremented or decremented.
|
|
@@ -18,8 +21,17 @@ export class ShardedCounter {
|
|
|
18
21
|
*/
|
|
19
22
|
constructor(component, options) {
|
|
20
23
|
this.component = component;
|
|
21
|
-
this.
|
|
24
|
+
this.stickyShard = {};
|
|
25
|
+
const defaultShards = options?.defaultShards;
|
|
26
|
+
this.shardsForKey = (name) => {
|
|
27
|
+
const explicitShards = options?.shards?.[name];
|
|
28
|
+
return explicitShards ?? defaultShards;
|
|
29
|
+
};
|
|
22
30
|
}
|
|
31
|
+
shardsForKey;
|
|
32
|
+
// Keep track of the shard for each key, so multiple mutations on the same key
|
|
33
|
+
// will use the same shard.
|
|
34
|
+
stickyShard;
|
|
23
35
|
/**
|
|
24
36
|
* Increase the counter for key `name` by `count`.
|
|
25
37
|
* If `count` is negative, the counter will decrease.
|
|
@@ -28,12 +40,31 @@ export class ShardedCounter {
|
|
|
28
40
|
* @param count The amount to increment the counter by. Defaults to 1.
|
|
29
41
|
*/
|
|
30
42
|
async add(ctx, name, count = 1) {
|
|
31
|
-
const
|
|
32
|
-
return ctx.runMutation(this.component.public.add, {
|
|
43
|
+
const shard = await ctx.runMutation(this.component.public.add, {
|
|
33
44
|
name,
|
|
34
45
|
count,
|
|
35
|
-
|
|
46
|
+
shard: this.stickyShard?.[name],
|
|
47
|
+
shards: this.shardsForKey(name),
|
|
36
48
|
});
|
|
49
|
+
this.stickyShard[name] = shard;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Decrease the counter for key `name` by `count`.
|
|
53
|
+
*/
|
|
54
|
+
async subtract(ctx, name, count = 1) {
|
|
55
|
+
return this.add(ctx, name, -count);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Increment the counter for key `name` by 1.
|
|
59
|
+
*/
|
|
60
|
+
async inc(ctx, name) {
|
|
61
|
+
return this.add(ctx, name, 1);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Decrement the counter for key `name` by 1.
|
|
65
|
+
*/
|
|
66
|
+
async dec(ctx, name) {
|
|
67
|
+
return this.add(ctx, name, -1);
|
|
37
68
|
}
|
|
38
69
|
/**
|
|
39
70
|
* Gets the counter for key `name`.
|
|
@@ -44,6 +75,50 @@ export class ShardedCounter {
|
|
|
44
75
|
async count(ctx, name) {
|
|
45
76
|
return ctx.runQuery(this.component.public.count, { name });
|
|
46
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Redistribute counts evenly across the counter's shards.
|
|
80
|
+
*
|
|
81
|
+
* If there were more shards for this counter at some point, those shards
|
|
82
|
+
* will be removed.
|
|
83
|
+
*
|
|
84
|
+
* If there were fewer shards for this counter, or if the random distribution
|
|
85
|
+
* of counts is uneven, the counts will be redistributed evenly.
|
|
86
|
+
*
|
|
87
|
+
* This operation reads and writes all shards, so it can cause contention if
|
|
88
|
+
* called too often.
|
|
89
|
+
*/
|
|
90
|
+
async rebalance(ctx, name) {
|
|
91
|
+
await ctx.runMutation(this.component.public.rebalance, {
|
|
92
|
+
name,
|
|
93
|
+
shards: this.shardsForKey(name),
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Clear the counter for key `name`.
|
|
98
|
+
*
|
|
99
|
+
* @param name The key to clear the counter for.
|
|
100
|
+
*/
|
|
101
|
+
async reset(ctx, name) {
|
|
102
|
+
await ctx.runMutation(this.component.public.reset, { name });
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Estimate the count of a counter by only reading from a subset of shards,
|
|
106
|
+
* and extrapolating the total count.
|
|
107
|
+
*
|
|
108
|
+
* After a `rebalance`, or if there were a lot of data points to yield a
|
|
109
|
+
* random distribution across shards, this should be a good approximation of
|
|
110
|
+
* the total count. If there are few data points, which are not evenly
|
|
111
|
+
* distributed across shards, this will be a poor approximation.
|
|
112
|
+
*
|
|
113
|
+
* Use this to reduce contention when reading the counter.
|
|
114
|
+
*/
|
|
115
|
+
async estimateCount(ctx, name, readFromShards = 1) {
|
|
116
|
+
return await ctx.runQuery(this.component.public.estimateCount, {
|
|
117
|
+
name,
|
|
118
|
+
shards: this.shardsForKey(name),
|
|
119
|
+
readFromShards,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
47
122
|
/**
|
|
48
123
|
* Returns an object with methods to update and query the counter for key
|
|
49
124
|
* `name`. For fixed keys, you can call `counter.for("<key>")` to get methods
|
|
@@ -84,6 +159,34 @@ export class ShardedCounter {
|
|
|
84
159
|
* contend with all mutations that update the counter for this key.
|
|
85
160
|
*/
|
|
86
161
|
count: async (ctx) => this.count(ctx, name),
|
|
162
|
+
/**
|
|
163
|
+
* Reset the counter for this key.
|
|
164
|
+
*/
|
|
165
|
+
reset: async (ctx) => this.reset(ctx, name),
|
|
166
|
+
/**
|
|
167
|
+
* Redistribute counts evenly across the counter's shards.
|
|
168
|
+
*
|
|
169
|
+
* This operation reads and writes all shards, so it can cause contention
|
|
170
|
+
* if called too often.
|
|
171
|
+
*/
|
|
172
|
+
rebalance: async (ctx) => this.rebalance(ctx, name),
|
|
173
|
+
/**
|
|
174
|
+
* Estimate the counter by only reading from a subset of shards,
|
|
175
|
+
* and extrapolating the total count.
|
|
176
|
+
*
|
|
177
|
+
* Use this to reduce contention when reading the counter.
|
|
178
|
+
*/
|
|
179
|
+
estimateCount: async (ctx, readFromShards = 1) => this.estimateCount(ctx, name, readFromShards),
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
trigger(name) {
|
|
183
|
+
return async (ctx, change) => {
|
|
184
|
+
if (change.operation === "insert") {
|
|
185
|
+
await this.inc(ctx, name);
|
|
186
|
+
}
|
|
187
|
+
else if (change.operation === "delete") {
|
|
188
|
+
await this.dec(ctx, name);
|
|
189
|
+
}
|
|
87
190
|
};
|
|
88
191
|
}
|
|
89
192
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/client/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/client/index.ts"],"names":[],"mappings":"AAYA;;;GAGG;AACH,MAAM,OAAO,cAAc;IAiBf;IAhBV;;;;;;;;;;;;;;OAcG;IACH,Y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EAAE,IAAI,CAAC,CAAC;aAC3B;QACH,CAAC,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../../src/component/_generated/api.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../../src/component/_generated/api.js"],"names":[],"mappings":"AAYA;;;;;;;GAOG;AACH,iDAA0B;AAC1B,sDAA+B;AAC/B;;EAA8C"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/* prettier-ignore-start */
|
|
2
1
|
/* eslint-disable */
|
|
3
2
|
/**
|
|
4
3
|
* Generated `api` utility.
|
|
@@ -20,5 +19,4 @@ import { anyApi, componentsGeneric } from "convex/server";
|
|
|
20
19
|
export const api = anyApi;
|
|
21
20
|
export const internal = anyApi;
|
|
22
21
|
export const components = componentsGeneric();
|
|
23
|
-
/* prettier-ignore-end */
|
|
24
22
|
//# sourceMappingURL=api.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../../../src/component/_generated/api.js"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../../../src/component/_generated/api.js"],"names":[],"mappings":"AAAA,oBAAoB;AACpB;;;;;;;GAOG;AAEH,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAE1D;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,GAAG,GAAG,MAAM,CAAC;AAC1B,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC;AAC/B,MAAM,CAAC,MAAM,UAAU,GAAG,iBAAiB,EAAE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../../src/component/_generated/server.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../../src/component/_generated/server.js"],"names":[],"mappings":"AAqBA;;;;;;;GAOG;AACH,wEAAkC;AAElC;;;;;;;GAOG;AACH,kFAAkD;AAElD;;;;;;;GAOG;AACH,8EAAwC;AAExC;;;;;;;GAOG;AACH,wFAAwD;AAExD;;;;;;;;;;GAUG;AACH,0EAAoC;AAEpC;;;;;GAKG;AACH,oFAAoD;AAEpD;;;;;;GAMG;AACH,8MAA4C"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/* prettier-ignore-start */
|
|
2
1
|
/* eslint-disable */
|
|
3
2
|
/**
|
|
4
3
|
* Generated utilities for implementing server-side Convex query and mutation functions.
|
|
@@ -72,5 +71,4 @@ export const internalAction = internalActionGeneric;
|
|
|
72
71
|
* @returns The wrapped endpoint function. Route a URL path to this function in `convex/http.js`.
|
|
73
72
|
*/
|
|
74
73
|
export const httpAction = httpActionGeneric;
|
|
75
|
-
/* prettier-ignore-end */
|
|
76
74
|
//# sourceMappingURL=server.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../../../src/component/_generated/server.js"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../../../src/component/_generated/server.js"],"names":[],"mappings":"AAAA,oBAAoB;AACpB;;;;;;;GAOG;AAEH,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,YAAY,EACZ,eAAe,EACf,qBAAqB,EACrB,uBAAuB,EACvB,oBAAoB,EACpB,iBAAiB,GAClB,MAAM,eAAe,CAAC;AAEvB;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,YAAY,CAAC;AAElC;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,oBAAoB,CAAC;AAElD;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,eAAe,CAAC;AAExC;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,uBAAuB,CAAC;AAExD;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,aAAa,CAAC;AAEpC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,qBAAqB,CAAC;AAEpD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,iBAAiB,CAAC"}
|
|
@@ -1,10 +1,23 @@
|
|
|
1
1
|
export declare const DEFAULT_SHARD_COUNT = 16;
|
|
2
2
|
export declare const add: import("convex/server").RegisteredMutation<"public", {
|
|
3
|
+
shard?: number | undefined;
|
|
3
4
|
shards?: number | undefined;
|
|
4
5
|
name: string;
|
|
5
6
|
count: number;
|
|
6
|
-
}, Promise<
|
|
7
|
+
}, Promise<number>>;
|
|
7
8
|
export declare const count: import("convex/server").RegisteredQuery<"public", {
|
|
8
9
|
name: string;
|
|
9
10
|
}, Promise<number>>;
|
|
11
|
+
export declare const rebalance: import("convex/server").RegisteredMutation<"public", {
|
|
12
|
+
shards?: number | undefined;
|
|
13
|
+
name: string;
|
|
14
|
+
}, Promise<void>>;
|
|
15
|
+
export declare const reset: import("convex/server").RegisteredMutation<"public", {
|
|
16
|
+
name: string;
|
|
17
|
+
}, Promise<void>>;
|
|
18
|
+
export declare const estimateCount: import("convex/server").RegisteredQuery<"public", {
|
|
19
|
+
shards?: number | undefined;
|
|
20
|
+
readFromShards?: number | undefined;
|
|
21
|
+
name: string;
|
|
22
|
+
}, Promise<number>>;
|
|
10
23
|
//# sourceMappingURL=public.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"public.d.ts","sourceRoot":"","sources":["../../../src/component/public.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,mBAAmB,KAAK,CAAC;AAEtC,eAAO,MAAM,GAAG
|
|
1
|
+
{"version":3,"file":"public.d.ts","sourceRoot":"","sources":["../../../src/component/public.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,mBAAmB,KAAK,CAAC;AAEtC,eAAO,MAAM,GAAG;;;;;mBA6Bd,CAAC;AAEH,eAAO,MAAM,KAAK;;mBAUhB,CAAC;AAEH,eAAO,MAAM,SAAS;;;iBA2BpB,CAAC;AAEH,eAAO,MAAM,KAAK;;iBAWhB,CAAC;AAEH,eAAO,MAAM,aAAa;;;;mBA2BxB,CAAC"}
|