MCPcopy
hub / github.com/nats-io/nats.go / CreateObjectStore

Method CreateObjectStore

object.go:248–301  ·  view source on GitHub ↗

CreateObjectStore will create an object store.

(cfg *ObjectStoreConfig)

Source from the content-addressed store, hash-verified

246
247// CreateObjectStore will create an object store.
248func (js *js) CreateObjectStore(cfg *ObjectStoreConfig) (ObjectStore, error) {
249 if !js.nc.serverMinVersion(2, 6, 2) {
250 return nil, ErrNeeds262
251 }
252 if cfg == nil {
253 return nil, ErrObjectConfigRequired
254 }
255 if !validBucketRe.MatchString(cfg.Bucket) {
256 return nil, ErrInvalidStoreName
257 }
258
259 name := cfg.Bucket
260 chunks := fmt.Sprintf(objAllChunksPreTmpl, name)
261 meta := fmt.Sprintf(objAllMetaPreTmpl, name)
262
263 // We will set explicitly some values so that we can do comparison
264 // if we get an "already in use" error and need to check if it is same.
265 // See kv
266 replicas := cfg.Replicas
267 if replicas == 0 {
268 replicas = 1
269 }
270 maxBytes := cfg.MaxBytes
271 if maxBytes == 0 {
272 maxBytes = -1
273 }
274 var compression StoreCompression
275 if cfg.Compression {
276 compression = S2Compression
277 }
278 scfg := &StreamConfig{
279 Name: fmt.Sprintf(objNameTmpl, name),
280 Description: cfg.Description,
281 Subjects: []string{chunks, meta},
282 MaxAge: cfg.TTL,
283 MaxBytes: maxBytes,
284 Storage: cfg.Storage,
285 Replicas: replicas,
286 Placement: cfg.Placement,
287 Discard: DiscardNew,
288 AllowRollup: true,
289 AllowDirect: true,
290 Metadata: cfg.Metadata,
291 Compression: compression,
292 }
293
294 // Create our stream.
295 _, err := js.AddStream(scfg)
296 if err != nil {
297 return nil, err
298 }
299
300 return &obs{name: name, stream: scfg.Name, js: js}, nil
301}
302
303// ObjectStore will look up and bind to an existing object store instance.
304func (js *js) ObjectStore(bucket string) (ObjectStore, error) {

Callers

nothing calls this directly

Calls 2

AddStreamMethod · 0.95
serverMinVersionMethod · 0.80

Tested by

no test coverage detected