Conversation
d02b0ff to
2fd1efb
Compare
8cc22b8 to
3935ba2
Compare
63232fe to
c7ba70b
Compare
c7ba70b to
9c72769
Compare
| c := *d | ||
| c.namespace = namespace | ||
| return &c | ||
| } |
There was a problem hiding this comment.
Lmk if this is how you were thinking to have the same underlying cache and inject the namespace from the registry.
There was a problem hiding this comment.
Yep this seems like the cleanest way!
| Put PutCmd `cmd:"" help:"Upload object to cache." group:"Operations:"` | ||
| Delete DeleteCmd `cmd:"" help:"Remove object from cache." group:"Operations:"` | ||
| URL string `help:"Remote cache server URL." default:"http://127.0.0.1:8080"` | ||
| Namespace string `help:"Namespace for organizing cache objects." default:""` |
There was a problem hiding this comment.
Do you think this should be a positional arg in each subcommand instead? Or if not, it should have a short flag so it's easy to use.
Subcommand:
cachew get <namespace> <key>
Flag:
cachew -n <namespace> get <key>
I feel like 99% of the time you're going to need a namespace, so the former is probably preferable.
| Stat StatCmd `cmd:"" help:"Show metadata for cached object." group:"Operations:"` | ||
| Put PutCmd `cmd:"" help:"Upload object to cache." group:"Operations:"` | ||
| Delete DeleteCmd `cmd:"" help:"Remove object from cache." group:"Operations:"` | ||
| ListNamespaces ListNamespacesCmd `cmd:"" help:"List available namespaces in cache." group:"Operations:"` |
There was a problem hiding this comment.
Rename this to Namespaces.
| ListNamespaces ListNamespacesCmd `cmd:"" help:"List available namespaces in cache." group:"Operations:"` | |
| Namespaces ListNamespacesCmd `cmd:"" help:"List available namespaces in cache." group:"Operations:"` |
| if err := d.db.deleteAll(sizeEvictedEntries); err != nil { | ||
| return errors.Errorf("failed to delete size-evicted metadata: %w", err) |
There was a problem hiding this comment.
Should this call deleteExpiredEntries like the other one?
| c := *d | ||
| c.namespace = namespace | ||
| return &c | ||
| } |
There was a problem hiding this comment.
Yep this seems like the cleanest way!
| } | ||
|
|
||
| namespaceBucket := tx.Bucket(namespaceBucketName) | ||
| return errors.WithStack(namespaceBucket.Put(dbKey, []byte(namespace))) |
There was a problem hiding this comment.
It's not clear to me why we need this extra bucket? AFAICT it's basically storing <namespace>/<sha> -> <namespace> but if we have the namespace in the key, we can just extract it?
There was a problem hiding this comment.
OTOH a <namespace> -> true mapping might be useful, though we could probably just keep that in memory computed from the initial walk, as the number of namespaces is never going to be very high.
| var key Key | ||
|
|
||
| // Check format: composite "namespace/hexkey" or raw 32-byte key | ||
| slashIdx := bytes.IndexByte(k, '/') |
There was a problem hiding this comment.
Using bytes.Cut(k, []byte("/")) would replace most of this switch here.
| func TestDiskNamespaceIsolation(t *testing.T) { | ||
| dir := t.TempDir() | ||
| _, ctx := logging.Configure(t.Context(), logging.Config{Level: slog.LevelDebug}) | ||
|
|
||
| // Create base cache | ||
| baseCache, err := cache.NewDisk(ctx, cache.DiskConfig{ | ||
| Root: dir, |
There was a problem hiding this comment.
Namespace tests should be moved into the cachetest suite so that it tests namespacing uniformly across all implementations.
| // Namespace creates a namespaced view (which is ignored by remote cache). | ||
| // Remote cache ignores namespaces since the server-side API v1 handles namespacing. | ||
| func (c *Remote) Namespace(_ string) Cache { | ||
| // Remote cache doesn't use namespacing on client side |
There was a problem hiding this comment.
Is this true? How else would the namespace get conveyed to the server?
| for ns := range namespaceSet { | ||
| namespaces = append(namespaces, ns) | ||
| } | ||
| return namespaces, nil |
There was a problem hiding this comment.
Always good to stablesort values out of a map so tests don't become flaky.
| @@ -37,6 +37,7 @@ func NewAPIV1(ctx context.Context, _ struct{}, cache cache.Cache, mux Mux) (*API | |||
| mux.Handle("POST /api/v1/object/{key}", http.HandlerFunc(s.putObject)) | |||
There was a problem hiding this comment.
It doesn't look like namespaces get through to the server in any way?
| mux.Handle("POST /api/v1/object/{key}", http.HandlerFunc(s.putObject)) | |
| mux.Handle("POST /api/v1/object/{namespace}/{key}", http.HandlerFunc(s.putObject)) |
Testing
Per strategy name directory in the cache folder