Skip to content

Commit 1695a58

Browse files
author
Aalyria Technologies, Inc
committed
Import changes.
- 2d2e88908cd1911ca29161030dc47078cd8f61f6 - 090224466e5778e6524feb17ad5bc05492410583 GitOrigin-RevId: 2d2e88908cd1911ca29161030dc47078cd8f61f6
1 parent 5df6557 commit 1695a58

5 files changed

Lines changed: 21 additions & 9 deletions

File tree

tools/nbictl/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ Sync all model entities and relationships from file and directory arguments.
135135

136136
**--format**="": The format to use for encoding and decoding protobuf messages. One of [text, json, binary]. (default: "text")
137137

138+
**--max-concurrency, -j, --max_concurrency**="": Limit the number of in-flight requests at once. (default: 100)
139+
138140
**--recursive, -r**: descend recursively into directory arguments
139141

140142
**--verbose, -v**: increase verbosity
@@ -161,6 +163,8 @@ Sync all provisioning resources from file and directory arguments.
161163

162164
**--format**="": The format to use for encoding and decoding protobuf messages. One of [text, json, binary]. (default: "text")
163165

166+
**--max-concurrency, -j, --max_concurrency**="": Limit the number of in-flight requests at once. (default: 100)
167+
164168
**--recursive, -r**: descend recursively into directory arguments
165169

166170
**--verbose, -v**: increase verbosity

tools/nbictl/model.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,7 @@ func ModelSync(appCtx *cli.Context) error {
445445
deleteMode := appCtx.Bool("delete")
446446
dryRunMode := appCtx.Bool("dry-run")
447447
verboseMode := appCtx.Bool("verbose")
448+
maxConcurrency := appCtx.Int("max-concurrency")
448449
printMode := dryRunMode || verboseMode
449450

450451
marshaller, err := marshallerForFormat(appCtx.String("format"))
@@ -545,7 +546,7 @@ func ModelSync(appCtx *cli.Context) error {
545546
errs := []error{}
546547

547548
// Delete relationships before deleting entities.
548-
deleteRelationshipsPool := pool.New().WithErrors()
549+
deleteRelationshipsPool := pool.New().WithErrors().WithMaxGoroutines(maxConcurrency)
549550
if deleteMode {
550551
relationshipsToBeDeleted := remoteRelationshipKeys.Difference(localRelationshipKeys)
551552
for relationship := range relationshipsToBeDeleted.Iter() {
@@ -568,7 +569,7 @@ func ModelSync(appCtx *cli.Context) error {
568569
errs = append(errs, deleteRelationshipsPool.Wait())
569570

570571
// Update entities.
571-
updatePool := pool.New().WithErrors()
572+
updatePool := pool.New().WithErrors().WithMaxGoroutines(maxConcurrency)
572573
entitiesInCommon := localEntityKeys.Intersect(remoteEntityKeys)
573574
for entity := range entitiesInCommon.Iter() {
574575
updatePool.Go(func() error {
@@ -589,12 +590,11 @@ func ModelSync(appCtx *cli.Context) error {
589590
}
590591

591592
// Maybe delete entities (and prune collaterally deleted relationships)
592-
deleteEntitiesPool := pool.New().WithErrors()
593593
if deleteMode {
594594
entitiesToBeDeleted := remoteEntityKeys.Difference(localEntityKeys)
595595

596596
for entity := range entitiesToBeDeleted.Iter() {
597-
deleteEntitiesPool.Go(func() error {
597+
updatePool.Go(func() error {
598598
if printMode {
599599
fmt.Printf("delete entity: %s\n", entity)
600600
}
@@ -613,10 +613,9 @@ func ModelSync(appCtx *cli.Context) error {
613613
}
614614

615615
errs = append(errs, updatePool.Wait())
616-
errs = append(errs, deleteEntitiesPool.Wait())
617616

618617
// Add entities.
619-
addEntitiesPool := pool.New().WithErrors()
618+
addEntitiesPool := pool.New().WithErrors().WithMaxGoroutines(maxConcurrency)
620619
entitiesToBeAdded := localEntityKeys.Difference(remoteEntityKeys)
621620
for entity := range entitiesToBeAdded.Iter() {
622621
addEntitiesPool.Go(func() error {
@@ -637,7 +636,7 @@ func ModelSync(appCtx *cli.Context) error {
637636
errs = append(errs, addEntitiesPool.Wait())
638637

639638
// Add relationships.
640-
addRelationshipsPool := pool.New().WithErrors()
639+
addRelationshipsPool := pool.New().WithErrors().WithMaxGoroutines(maxConcurrency)
641640
relationshipsToBeAdded := localRelationshipKeys.Difference(remoteRelationshipKeys)
642641
for relationship := range relationshipsToBeAdded.Iter() {
643642
addRelationshipsPool.Go(func() error {

tools/nbictl/nbictl.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ func App() *cli.App {
102102
Usage: "increase verbosity",
103103
Aliases: []string{"v"},
104104
}
105+
concurrencyFlag := &cli.IntFlag{
106+
Name: "max-concurrency",
107+
Aliases: []string{"j", "max_concurrency"},
108+
Value: 100,
109+
Usage: "Limit the number of in-flight requests at once.",
110+
}
105111

106112
return &cli.App{
107113
Name: appName,
@@ -315,6 +321,7 @@ func App() *cli.App {
315321
formatFlag,
316322
dryrunFlag,
317323
verboseFlag,
324+
concurrencyFlag,
318325
&cli.BoolFlag{
319326
Name: "delete",
320327
Usage: "delete entities and relationships from remote instance not present in local sources",
@@ -354,6 +361,7 @@ func App() *cli.App {
354361
formatFlag,
355362
dryrunFlag,
356363
verboseFlag,
364+
concurrencyFlag,
357365
&cli.BoolFlag{
358366
Name: "delete",
359367
Usage: "delete resources from remote instance not present in local sources",

tools/nbictl/provisioning.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,7 @@ func ProvisioningSync(appCtx *cli.Context) error {
436436
deleteMode := appCtx.Bool("delete")
437437
dryRunMode := appCtx.Bool("dry-run")
438438
verboseMode := appCtx.Bool("verbose")
439+
maxConcurrency := appCtx.Int("max-concurrency")
439440
printMode := dryRunMode || verboseMode
440441

441442
// TODO: restructure these computations for scalability.
@@ -504,7 +505,7 @@ func ProvisioningSync(appCtx *cli.Context) error {
504505
errs = append(errs, err)
505506
}
506507

507-
p := pool.New().WithErrors()
508+
p := pool.New().WithErrors().WithMaxGoroutines(maxConcurrency)
508509

509510
///
510511
// Update resources.

version.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ MAJOR = 19
2525
# -------------------------------------------------------------
2626
# This allows to publish bugfixes to the released version
2727
# through increments of PATCH segment.
28-
MINOR = 10
28+
MINOR = 11
2929

3030
# Monotonic ID of bugfixes applied to each MAJOR.MINOR release.
3131
# -------------------------------------------------------------

0 commit comments

Comments
 (0)