Skip to content

Commit e73b1fe

Browse files
authored
chore: clarify and update the storm tracking cache (#295)
* chore: clarify and update the storm tracking cache
1 parent ef96ae8 commit e73b1fe

File tree

1 file changed

+48
-4
lines changed

1 file changed

+48
-4
lines changed

framework/storm-tracking-cryptographic-materials-cache.md

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77

88
### Changelog
99

10+
- 0.2.0
11+
12+
- Add Time Units
13+
- Clarify Inflight TTL and Grace Interval
14+
1015
- 0.1.0
1116
- Initial record
1217
- [Thread Safe Cache](../changes/2023-06-19_thread_safe_cache/change.md)
@@ -18,7 +23,8 @@ is a built-in implementation of the [CMC interface](cryptographic-materials-cach
1823
provided by the AWS Encryption SDK.
1924

2025
It provides thread safe access to a [Local CMC](local-cryptographic-materials-cache.md),
21-
and prevents excessive parallel requests to the underlying cryptographic materials provider.
26+
prevents excessive parallel requests to the underlying cryptographic materials provider,
27+
and prevents redundant requests to the underlying cryptographic materials provider for the same key.
2228

2329
## Definitions
2430

@@ -41,6 +47,10 @@ Initialization MUST also provide
4147
- [Inflight TTL](#inflight-ttl)
4248
- [sleepMilli](#sleepmilli)
4349

50+
Initialization MUST optionally accept the following values:
51+
52+
- [timeUnits](#time units)
53+
4454
The implementation MUST instantiate a [Local CMC](local-cryptographic-materials-cache.md)
4555
to do the actual caching.
4656

@@ -53,24 +63,41 @@ attempts will be made to refresh the cache.
5363

5464
This should be significantly less than the TTL for any item put into the cache.
5565

66+
The Grace Period should be at least a few times larger than the Grace Interval,
67+
so that if something goes wrong with the first request, a second or third request will be made.
68+
5669
### Grace Interval
5770

5871
A number of seconds (at least 1, default 1).
5972

60-
While within the [grace period](#grace-period),
61-
attempts to refresh the cache are made no more often than once per interval.
73+
An entry that has been in flight for this long is no longer considered in flight.
74+
75+
While within the [grace period](#grace-period), after this period another request is made.
76+
77+
While doing the initial fetch for a key, after this period another request is made.
78+
79+
The Grace Interval should be larger than the longest time expected for a request to the underlying cryptographic materials provider.
6280

6381
### FanOut
6482

6583
A number (at least 1, default 20).
6684

6785
The maximum number of individual keys for which lookups can be in flight.
6886

87+
Other requests are blocked until the number of unique keys with outstanding requests drops below this number,
88+
or until the amount of time that request has been outstanding exceeds the [Inflight TTL](#inflight-ttl).
89+
6990
### Inflight TTL
7091

7192
A number (at least 1, default 20).
7293

73-
An entry that has been in flight for this long is no longer considered in flight.
94+
A request that has been in flight for this long returns an "InFlightTTL exceeded" error.
95+
96+
If a thread has been sleeping because other threads are allegedly working on the same key,
97+
it will give up and return an error after this amount of time.
98+
99+
The Inflight TTL should be at least a few times larger than the Grace Interval,
100+
so that if something goes wrong with the first request, a second or third request will be made.
74101

75102
### SleepMilli
76103

@@ -80,6 +107,20 @@ If the implementation must block, and no more intelligent signaling is used,
80107
then the implementation should sleep for this many milliseconds before
81108
reexamining the state of the cache.
82109

110+
SleepMilli MUST NOT be affected by [timeUnits](#time units)
111+
112+
### Time Units
113+
114+
Time Units MUST be either `Seconds` or `Milliseconds` and applies to
115+
116+
- [Grace Period](#grace-period)
117+
- [Grace Interval](#grace-interval)
118+
- [Inflight TTL](#inflight-ttl)
119+
120+
If unset, or set to `Seconds`, the above values MUST be interpreted as seconds.
121+
122+
If set to `Milliseconds`, the above values MUST be interpreted as milliseconds.
123+
83124
## Consistency
84125

85126
The settings need to be consistent.
@@ -171,6 +212,9 @@ one thread receives NoSuchEntry, while others are blocked until an entry appears
171212
- If the key _is not_ inflight
172213
GetCacheEntry MUST return NoSuchEntry and mark that key as inflight at the current time.
173214

215+
- If the key _is_ inflight
216+
and the time spent so far exceeds the [Inflight TTL](#inflight-ttl), the operation MUST fail.
217+
174218
- If the key _is_ inflight
175219
and the current time _is_ [within the grace interval](#within-grace-interval)
176220
GetCacheEntry MUST block until a [FanOut](#fanout) slot is available, or the key appears in the cache.

0 commit comments

Comments
 (0)