Skip to content

Commit 48c7654

Browse files
uc-build-userjwangxx
authored andcommitted
Sync monorepo state at 4721a746083d39904866cbe387288c8f6f5566a6
1 parent cdee50c commit 48c7654

File tree

27 files changed

+1384
-521
lines changed

27 files changed

+1384
-521
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
# Changelog
22

3+
## 1.3.0 - 28-06-2024
4+
5+
- Retry getting access token on EOF type network errors which occur when connection is lost.
6+
- Breaking change: RetryNetworkErrors option for jsonclient now takes a boolean, and the option is on by default
7+
38
## 1.2.0 - 09-04-2024
49

10+
- Update userstore sample to exercise partial update columns
511
- Add methods for creating, retrieving, updating, and deleting ColumnDataTypes
612
- Add DataType field to Column that refers to a ColumnDataType
713
- Add InputDataType and OutputDataType fields to Transformer that refer to ColumnDataTypes

authz/cache_name_provider.go

Lines changed: 108 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,28 @@ import (
1111

1212
const (
1313
// CachePrefix is the prefix for all keys in authz cache
14-
CachePrefix = "authz"
15-
objTypePrefix = "OBJTYPE" // Primary key for object type
16-
objTypeCollectionKeyString = "OBJTYPE_COL" // Global collection for object type
17-
edgeTypePrefix = "EDGETYPE" // Primary key for edge type
18-
edgeTypeCollectionKeyString = "EDGETYPE_COL" // Global collection for edge type
19-
objPrefix = "OBJ" // Primary key for object
20-
objCollectionKeyString = "OBJ_COL" // Global collection for object
21-
objEdgeCollection = "OBJEDGES" // Per object collection of all in/out edges
22-
perObjectEdgesPrefix = "E" // Per object collection of source/target edges
23-
perObjectPathPrefix = "P" // Per object collection containing path for a particular source/target/attribute
24-
edgePrefix = "EDGE" // Primary key for edge
25-
edgeCollectionKeyString = "EDGE_COL" // Global collection for edge
26-
orgPrefix = "ORG" // Primary key for organization
27-
orgCollectionKeyString = "ORG_COL" // Global collection for organizations
28-
dependencyPrefix = "DEP" // Shared dependency key prefix among all items
29-
isModifiedPrefix = "MOD" // Shared is modified key prefix among all items
14+
CachePrefix = "authz"
15+
objTypePrefix = "OBJTYPE" // Primary key for object type
16+
objTypeCollectionKeyString = "OBJTYPE_COL" // Global collection for object type
17+
edgeTypePrefix = "EDGETYPE" // Primary key for edge type
18+
edgeTypeCollectionKeyString = "EDGETYPE_COL" // Global collection for edge type
19+
objPrefix = "OBJ" // Primary key for object
20+
objCollectionKeyString = "OBJ_COL" // Global collection for object
21+
objEdgeCollection = "OBJEDGES" // Per object collection of all in/out edges
22+
perObjectEdgesPrefix = "E" // Per object collection of source/target edges
23+
perObjectPathPrefix = "P" // Per object collection containing path for a particular source/target/attribute
24+
edgePrefix = "EDGE" // Primary key for edge
25+
edgeCollectionKeyString = "EDGE_COL" // Global collection for edge
26+
edgeCollectionPagesPrefixString = "PAGES" // Pages making up global collection of edges
27+
orgPrefix = "ORG" // Primary key for organization
28+
orgCollectionKeyString = "ORG_COL" // Global collection for organizations
29+
dependencyPrefix = "DEP" // Shared dependency key prefix among all items
30+
isModifiedPrefix = "MOD" // Shared is modified key prefix among all items
3031
)
3132

3233
// CacheNameProvider is the base implementation of the CacheNameProvider interface
3334
type CacheNameProvider struct {
35+
cache.NoRateLimitKeyNameProvider
3436
basePrefix string // Base prefix for all keys TenantID_OrgID
3537
}
3638

@@ -73,6 +75,8 @@ const (
7375
DependencyKeyID = "DependencyKeyID"
7476
// IsModifiedKeyID is the key value indicating change in last TTL
7577
IsModifiedKeyID = "IsModifiedKeyID"
78+
// IsModifiedCollectionKeyID is the key value indicating change for global colleciton in last TTL
79+
IsModifiedCollectionKeyID = "IsModifiedCollectionKeyID"
7680
// ObjectTypeCollectionKeyID is the key for global collection of object types
7781
ObjectTypeCollectionKeyID = "ObjTypeCollectionKeyID"
7882
// EdgeTypeCollectionKeyID is the key for global collection of edge types
@@ -81,6 +85,10 @@ const (
8185
ObjectCollectionKeyID = "ObjCollectionKeyID"
8286
// EdgeCollectionKeyID is the key for global collection of edges
8387
EdgeCollectionKeyID = "EdgeCollectionKeyID"
88+
// EdgeCollectionPagesKeyID is the key for pages making up global collection of edges
89+
EdgeCollectionPagesKeyID = "EdgeCollectionPagesKeyID"
90+
// EdgeCollectionPageKeyID is the key for each individual page in the global collection of edges
91+
EdgeCollectionPageKeyID = "EdgeCollectionPageKeyID"
8492
// OrganizationCollectionKeyID is the key for global collection of organizations
8593
OrganizationCollectionKeyID = "OrgCollectionKeyID"
8694
// AttributePathObjToObjID is the primary key for attribute path
@@ -109,10 +117,13 @@ func (c *CacheNameProvider) GetAllKeyIDs() []string {
109117
EdgesObjToObjID,
110118
DependencyKeyID,
111119
IsModifiedKeyID,
120+
IsModifiedCollectionKeyID,
112121
ObjectTypeCollectionKeyID,
113122
EdgeTypeCollectionKeyID,
114123
ObjectCollectionKeyID,
115124
EdgeCollectionKeyID,
125+
EdgeCollectionPagesKeyID,
126+
EdgeCollectionPageKeyID,
116127
OrganizationCollectionKeyID,
117128
AttributePathObjToObjID,
118129
}
@@ -165,6 +176,10 @@ func (c *CacheNameProvider) GetKeyName(id cache.KeyNameID, components []string)
165176
return c.objCollectionKey()
166177
case EdgeCollectionKeyID:
167178
return c.edgeCollectionKey()
179+
case EdgeCollectionPagesKeyID:
180+
return c.edgeCollectionPagesKey()
181+
case EdgeCollectionPageKeyID:
182+
return c.edgeCollectionPageKey(components[0], components[1])
168183
case OrganizationCollectionKeyID:
169184
return c.orgCollectionKey()
170185
case ObjEdgesKeyID:
@@ -173,6 +188,8 @@ func (c *CacheNameProvider) GetKeyName(id cache.KeyNameID, components []string)
173188
return c.dependencyKey(components[0])
174189
case IsModifiedKeyID:
175190
return c.isModifiedKey(components[0])
191+
case IsModifiedCollectionKeyID:
192+
return c.isModifiedCollectionKey(components[0])
176193
case EdgeFullKeyID:
177194
return c.edgeFullKeyNameFromIDs(components[0], components[1], components[2])
178195
case AttributePathObjToObjID:
@@ -271,6 +288,20 @@ func (c *CacheNameProvider) edgeCollectionKey() cache.Key {
271288
return cache.Key(fmt.Sprintf("%v_%v", c.basePrefix, edgeCollectionKeyString))
272289
}
273290

291+
// edgeCollectionModifiedKey returns key name for edge collection
292+
func (c *CacheNameProvider) isModifiedCollectionKey(colKey string) cache.Key {
293+
return cache.Key(fmt.Sprintf("%v_%v", colKey, isModifiedPrefix))
294+
}
295+
296+
// edgeCollectionKey returns key name for edge collection
297+
func (c *CacheNameProvider) edgeCollectionPagesKey() cache.Key {
298+
return cache.Key(fmt.Sprintf("%v_%v_%v", c.basePrefix, edgeCollectionKeyString, edgeCollectionPagesPrefixString))
299+
}
300+
301+
func (c *CacheNameProvider) edgeCollectionPageKey(cursor string, limit string) cache.Key {
302+
return cache.Key(fmt.Sprintf("%v_%v_%v_%v", c.basePrefix, edgeCollectionKeyString, cursor, limit))
303+
}
304+
274305
// orgCollectionKey returns key name for edge collection
275306
func (c *CacheNameProvider) orgCollectionKey() cache.Key {
276307
return cache.Key(fmt.Sprintf("%v_%v", c.basePrefix, orgCollectionKeyString))
@@ -291,6 +322,11 @@ func (ot ObjectType) GetGlobalCollectionKey(c cache.KeyNameProvider) cache.Key {
291322
return c.GetKeyNameStatic(ObjectTypeCollectionKeyID)
292323
}
293324

325+
// GetGlobalCollectionPagesKey returns the global collection key name for object type
326+
func (ot ObjectType) GetGlobalCollectionPagesKey(c cache.KeyNameProvider) cache.Key {
327+
return "" // Unused since there is no pagination for object types
328+
}
329+
294330
// GetSecondaryKeys returns the secondary cache key names for object type
295331
func (ot ObjectType) GetSecondaryKeys(c cache.KeyNameProvider) []cache.Key {
296332
return []cache.Key{c.GetKeyNameWithString(ObjectTypeNameKeyID, ot.TypeName)}
@@ -311,6 +347,11 @@ func (ot ObjectType) GetIsModifiedKey(c cache.KeyNameProvider) cache.Key {
311347
return c.GetKeyNameWithID(IsModifiedKeyID, ot.ID)
312348
}
313349

350+
// GetIsModifiedCollectionKey returns the IsModifiedCollectionKeyID key name for object type
351+
func (ot ObjectType) GetIsModifiedCollectionKey(c cache.KeyNameProvider) cache.Key {
352+
return "" // Unused until we turn one page caching
353+
}
354+
314355
// GetDependencyKeys returns the list of keys for object type dependencies
315356
func (ot ObjectType) GetDependencyKeys(c cache.KeyNameProvider) []cache.Key {
316357
return []cache.Key{} // ObjectTypes don't depend on anything
@@ -331,6 +372,11 @@ func (et EdgeType) GetGlobalCollectionKey(c cache.KeyNameProvider) cache.Key {
331372
return c.GetKeyNameStatic(EdgeTypeCollectionKeyID)
332373
}
333374

375+
// GetGlobalCollectionPagesKey returns the global collection key name for edge type
376+
func (et EdgeType) GetGlobalCollectionPagesKey(c cache.KeyNameProvider) cache.Key {
377+
return "" // Unused since there is no pagination for edge types
378+
}
379+
334380
// GetPerItemCollectionKey returns the per item collection key name for edge type
335381
func (et EdgeType) GetPerItemCollectionKey(c cache.KeyNameProvider) cache.Key {
336382
return "" // Unused since there nothing stored per edge type, could store edges of this type in the future
@@ -351,6 +397,11 @@ func (et EdgeType) GetIsModifiedKey(c cache.KeyNameProvider) cache.Key {
351397
return c.GetKeyNameWithID(IsModifiedKeyID, et.ID)
352398
}
353399

400+
// GetIsModifiedCollectionKey returns the IsModifiedCollectionKeyID key name for edge type
401+
func (et EdgeType) GetIsModifiedCollectionKey(c cache.KeyNameProvider) cache.Key {
402+
return "" // Unused until we turn one page caching
403+
}
404+
354405
// GetDependencyKeys returns the list of keys for edge type dependencies
355406
func (et EdgeType) GetDependencyKeys(c cache.KeyNameProvider) []cache.Key {
356407
// EdgeTypes depend on source/target object types but we don't store that dependency because we currently flush the whole cache on object type delete
@@ -380,6 +431,11 @@ func (o Object) GetGlobalCollectionKey(c cache.KeyNameProvider) cache.Key {
380431
return c.GetKeyNameStatic(ObjectCollectionKeyID)
381432
}
382433

434+
// GetGlobalCollectionPagesKey returns the global collection key name for objects
435+
func (o Object) GetGlobalCollectionPagesKey(c cache.KeyNameProvider) cache.Key {
436+
return "" // Unused since there is no pagination for objects
437+
}
438+
383439
// GetPerItemCollectionKey returns the per item collection key name for object
384440
func (o Object) GetPerItemCollectionKey(c cache.KeyNameProvider) cache.Key {
385441
return c.GetKeyNameWithID(ObjEdgesKeyID, o.ID)
@@ -395,6 +451,11 @@ func (o Object) GetIsModifiedKey(c cache.KeyNameProvider) cache.Key {
395451
return c.GetKeyNameWithID(IsModifiedKeyID, o.ID)
396452
}
397453

454+
// GetIsModifiedCollectionKey returns the IsModifiedCollectionKeyID key name for object
455+
func (o Object) GetIsModifiedCollectionKey(c cache.KeyNameProvider) cache.Key {
456+
return "" // Unused until we turn one page caching
457+
}
458+
398459
// GetDependencyKeys returns the list of keys for object dependencies
399460
func (o Object) GetDependencyKeys(c cache.KeyNameProvider) []cache.Key {
400461
// Objects depend on object types but we don't store that dependency because we currently flush the whole cache on object type delete
@@ -416,6 +477,11 @@ func (e Edge) GetGlobalCollectionKey(c cache.KeyNameProvider) cache.Key {
416477
return c.GetKeyNameStatic(EdgeCollectionKeyID)
417478
}
418479

480+
// GetGlobalCollectionPagesKey returns the global collection key name for edge
481+
func (e Edge) GetGlobalCollectionPagesKey(c cache.KeyNameProvider) cache.Key {
482+
return c.GetKeyNameStatic(EdgeCollectionPagesKeyID)
483+
}
484+
419485
// GetPerItemCollectionKey returns the per item collection key name for edge
420486
func (e Edge) GetPerItemCollectionKey(c cache.KeyNameProvider) cache.Key {
421487
return ""
@@ -431,6 +497,11 @@ func (e Edge) GetIsModifiedKey(c cache.KeyNameProvider) cache.Key {
431497
return c.GetKeyNameWithID(IsModifiedKeyID, e.ID)
432498
}
433499

500+
// GetIsModifiedCollectionKey returns the IsModifiedCollectionKeyID key name for edge
501+
func (e Edge) GetIsModifiedCollectionKey(c cache.KeyNameProvider) cache.Key {
502+
return c.GetKeyNameWithString(IsModifiedCollectionKeyID, string(e.GetGlobalCollectionKey(c)))
503+
}
504+
434505
// GetDependencyKeys returns the list of keys for edge dependencies
435506
func (e Edge) GetDependencyKeys(c cache.KeyNameProvider) []cache.Key {
436507
// Edges depend on objects and edge types. We don't store edgetype dependency because we currently flush the whole cache on edge type delete
@@ -447,7 +518,7 @@ func (e Edge) TTL(c cache.TTLProvider) time.Duration {
447518
return c.TTL(EdgeTTL)
448519
}
449520

450-
// GetPrimaryKey returns the primary cache key name for edge
521+
// GetPrimaryKey returns the primary cache key name for path node
451522
func (e AttributePathNode) GetPrimaryKey(c cache.KeyNameProvider) cache.Key {
452523
return "" // Unused since AttributePathNode is not stored in cache directly
453524
}
@@ -457,6 +528,11 @@ func (e AttributePathNode) GetGlobalCollectionKey(c cache.KeyNameProvider) cache
457528
return ""
458529
}
459530

531+
// GetGlobalCollectionPagesKey returns the global collection key name for path node
532+
func (e AttributePathNode) GetGlobalCollectionPagesKey(c cache.KeyNameProvider) cache.Key {
533+
return "" // Unused since there is no pagination for path node
534+
}
535+
460536
// GetPerItemCollectionKey returns the per item collection key name for path node
461537
func (e AttributePathNode) GetPerItemCollectionKey(c cache.KeyNameProvider) cache.Key {
462538
return ""
@@ -472,6 +548,11 @@ func (e AttributePathNode) GetIsModifiedKey(c cache.KeyNameProvider) cache.Key {
472548
return ""
473549
}
474550

551+
// GetIsModifiedCollectionKey returns the IsModifiedCollectionKeyID key name for attribute path
552+
func (e AttributePathNode) GetIsModifiedCollectionKey(c cache.KeyNameProvider) cache.Key {
553+
return "" // Unused until we turn one page caching
554+
}
555+
475556
// GetDependencyKeys returns the list of keys for path node dependencies
476557
func (e AttributePathNode) GetDependencyKeys(c cache.KeyNameProvider) []cache.Key {
477558
// Path node depend on objects and edges.
@@ -501,6 +582,11 @@ func (o Organization) GetGlobalCollectionKey(c cache.KeyNameProvider) cache.Key
501582
return c.GetKeyNameStatic(OrganizationCollectionKeyID)
502583
}
503584

585+
// GetGlobalCollectionPagesKey returns the global collection key name for organization
586+
func (o Organization) GetGlobalCollectionPagesKey(c cache.KeyNameProvider) cache.Key {
587+
return "" // Unused since there is no pagination for organization
588+
}
589+
504590
// GetPerItemCollectionKey returns the per item collection key name for organization (none)
505591
func (o Organization) GetPerItemCollectionKey(c cache.KeyNameProvider) cache.Key {
506592
return ""
@@ -516,6 +602,11 @@ func (o Organization) GetIsModifiedKey(c cache.KeyNameProvider) cache.Key {
516602
return c.GetKeyNameWithID(IsModifiedKeyID, o.ID)
517603
}
518604

605+
// GetIsModifiedCollectionKey returns the IsModifiedCollectionKeyID key name for organization
606+
func (o Organization) GetIsModifiedCollectionKey(c cache.KeyNameProvider) cache.Key {
607+
return "" // Unused until we turn one page caching
608+
}
609+
519610
// GetDependencyKeys returns the list of keys for organization dependencies
520611
func (o Organization) GetDependencyKeys(c cache.KeyNameProvider) []cache.Key {
521612
return []cache.Key{}

authz/cache_ttl_provider.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package authz
22

33
import (
4+
"math/rand"
45
"time"
56

67
"userclouds.com/infra/cache"
@@ -13,11 +14,12 @@ type CacheTTLProvider struct {
1314
objTTL time.Duration
1415
edgeTTL time.Duration
1516
orgTTL time.Duration
17+
exprWindow time.Duration
1618
}
1719

1820
// NewCacheTTLProvider creates a new Configurablecache.CacheTTLProvider
19-
func NewCacheTTLProvider(objTypeTTL time.Duration, edgeTypeTTL time.Duration, objTTL time.Duration, edgeTTL time.Duration) *CacheTTLProvider {
20-
return &CacheTTLProvider{objTypeTTL: objTypeTTL, edgeTypeTTL: edgeTypeTTL, objTTL: objTTL, edgeTTL: edgeTTL, orgTTL: objTypeTTL}
21+
func NewCacheTTLProvider(objTypeTTL time.Duration, edgeTypeTTL time.Duration, objTTL time.Duration, edgeTTL time.Duration, exprWindow time.Duration) *CacheTTLProvider {
22+
return &CacheTTLProvider{objTypeTTL: objTypeTTL, edgeTypeTTL: edgeTypeTTL, objTTL: objTTL, edgeTTL: edgeTTL, orgTTL: objTypeTTL, exprWindow: exprWindow}
2123
}
2224

2325
const (
@@ -35,17 +37,22 @@ const (
3537

3638
// TTL returns the TTL for given type
3739
func (c *CacheTTLProvider) TTL(id cache.KeyTTLID) time.Duration {
40+
var shiftTTL time.Duration
41+
42+
if c.exprWindow != 0 {
43+
shiftTTL = time.Duration(rand.Intn(int(c.exprWindow.Nanoseconds())))
44+
}
3845
switch id {
3946
case ObjectTypeTTL:
40-
return c.objTypeTTL
47+
return c.objTypeTTL + shiftTTL
4148
case EdgeTypeTTL:
42-
return c.edgeTypeTTL
49+
return c.edgeTypeTTL + shiftTTL
4350
case ObjectTTL:
44-
return c.objTTL
51+
return c.objTTL + shiftTTL
4552
case EdgeTTL:
46-
return c.edgeTTL
53+
return c.edgeTTL + shiftTTL
4754
case OrganizationTTL:
48-
return c.orgTTL
55+
return c.orgTTL + shiftTTL
4956
}
5057
return cache.SkipCacheTTL
5158
}

0 commit comments

Comments
 (0)