Merge pull request #4239 from urbit/m/graph-join-backoff

graph: make the join thread back off
This commit is contained in:
matildepark 2021-01-21 13:27:59 -05:00 committed by GitHub
commit 84d23a9308
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 7 deletions

View File

@ -29,13 +29,16 @@
^- form:m ^- form:m
=/ pax =/ pax
(en-path:resource rid) (en-path:resource rid)
=/ hold=@dr ~s0..8000
|- ^- form:m |- ^- form:m
?> (lte hold ~m5)
=* loop $ =* loop $
;< u-group=(unit group) bind:m ;< u-group=(unit group) bind:m
(scry:strandio ,(unit group) (weld /gx/group-store/groups (snoc pax %noun))) (scry:strandio ,(unit group) (weld /gx/group-store/groups (snoc pax %noun)))
?^ u-group ?^ u-group
(pure:m ~) (pure:m ~)
;< ~ bind:m (sleep:strandio `@dr`(div ~s1 2)) ;< ~ bind:m (sleep:strandio hold)
=. hold (mul hold 2)
loop loop
:: ::
++ wait-for-md ++ wait-for-md
@ -44,13 +47,16 @@
^- form:m ^- form:m
=/ pax =/ pax
(en-path:resource rid) (en-path:resource rid)
=/ hold=@dr ~s0..8000
|- ^- form:m |- ^- form:m
?> (lte hold ~m5)
=* loop $ =* loop $
;< groups=(set path) bind:m ;< groups=(jug path md-resource) bind:m
(scry:strandio ,(set path) /gy/metadata-store/group-indices) (scry:strandio ,(jug path md-resource) /gy/metadata-store/group-indices)
?: (~(has in groups) pax) ?: (~(has by groups) pax)
(pure:m ~) (pure:m ~)
;< ~ bind:m (sleep:strandio `@dr`(div ~s1 2)) ;< ~ bind:m (sleep:strandio hold)
=. hold (mul hold 2)
loop loop
-- --
:: ::

View File

@ -3,8 +3,8 @@ import { StoreState } from '../store/type';
import { Patp, Path, PatpNoSig } from '~/types/noun'; import { Patp, Path, PatpNoSig } from '~/types/noun';
import _ from 'lodash'; import _ from 'lodash';
import {makeResource, resourceFromPath} from '../lib/group'; import {makeResource, resourceFromPath} from '../lib/group';
import {GroupPolicy, Enc, Post, NodeMap, Content} from '~/types'; import {GroupPolicy, Enc, Post, NodeMap, Content, Resource} from '~/types';
import { numToUd, unixToDa, decToUd, deSig } from '~/logic/lib/util'; import { numToUd, unixToDa, decToUd, deSig, resourceAsPath } from '~/logic/lib/util';
export const createBlankNodeWithChildPost = ( export const createBlankNodeWithChildPost = (
parentIndex: string = '', parentIndex: string = '',
@ -81,6 +81,8 @@ function moduleToMark(mod: string): string | undefined {
export default class GraphApi extends BaseApi<StoreState> { export default class GraphApi extends BaseApi<StoreState> {
joiningGraphs = new Set<string>();
private storeAction(action: any): Promise<any> { private storeAction(action: any): Promise<any> {
return this.action('graph-store', 'graph-update', action) return this.action('graph-store', 'graph-update', action)
} }
@ -138,11 +140,19 @@ export default class GraphApi extends BaseApi<StoreState> {
joinGraph(ship: Patp, name: string) { joinGraph(ship: Patp, name: string) {
const resource = makeResource(ship, name); const resource = makeResource(ship, name);
const rid = resourceAsPath(resource);
if(this.joiningGraphs.has(rid)) {
return Promise.resolve();
}
this.joiningGraphs.add(rid);
return this.viewAction('graph-join', { return this.viewAction('graph-join', {
join: { join: {
resource, resource,
ship, ship,
} }
}).then(res => {
this.joiningGraphs.delete(rid);
return res;
}); });
} }