You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
CreateBucketIfNotExists() currently tries to create the bucket as the first operation - instead of trying to find the bucket. For use cases where it's highly likely the bucket doesn't exist, it makes sense to create first, and on fail read.
However, having the reverse would be a really handy way to open buckets in cases where a lot of buckets are automatically generated and kept around (the system has repeated reads).
I plan on opening many longer-living buckets during runtime (I can't pre-caculated them to allocate them on startup). Since I will be reading these buckets a couple orders of magnitude more than I create them - I would rather not incur the double-seek penalty for trying to create, then read, every time I use the bucket.
The solution either seems to be:
To cache the bucket's existence: (if created { tx.Bucket(name) } else { tx.CreateBucketIfNotExists(name))
Or to try to read, and on fail create:
b := tx.Bucket(name)
if b == nil {
b, err := tx.CreateBucket(name)
}
As a side note unrelated to this: Either of these are prone to race conditions in a way that pre-allocating them on startup would solve, if only I could.
The text was updated successfully, but these errors were encountered:
@zwass I wasn't clear enough so I'm not exactly sure what I meant. However, I don't think there is an actual race-condition; as in an undefined data state. I think I was talking about the order that View or Update transactions could be issued.
CreateBucketIfNotExists() currently tries to create the bucket as the first operation - instead of trying to find the bucket. For use cases where it's highly likely the bucket doesn't exist, it makes sense to create first, and on fail read.
However, having the reverse would be a really handy way to open buckets in cases where a lot of buckets are automatically generated and kept around (the system has repeated reads).
I plan on opening many longer-living buckets during runtime (I can't pre-caculated them to allocate them on startup). Since I will be reading these buckets a couple orders of magnitude more than I create them - I would rather not incur the double-seek penalty for trying to create, then read, every time I use the bucket.
The solution either seems to be:
if created { tx.Bucket(name) } else { tx.CreateBucketIfNotExists(name)
)As a side note unrelated to this: Either of these are prone to race conditions in a way that pre-allocating them on startup would solve, if only I could.
The text was updated successfully, but these errors were encountered: