writeCache writes every Sequence in the cache to the underlying map.
(ctx context.Context)
| 405 | |
| 406 | // writeCache writes every Sequence in the cache to the underlying map. |
| 407 | func (pgs *Collection) writeCache(ctx context.Context) (err error) { |
| 408 | if len(pgs.accessedMap) == 0 { |
| 409 | return nil |
| 410 | } |
| 411 | mapEditor := pgs.underlyingMap.Editor() |
| 412 | for _, seq := range pgs.accessedMap { |
| 413 | data, err := seq.Serialize(ctx) |
| 414 | if err != nil { |
| 415 | return err |
| 416 | } |
| 417 | h, err := pgs.ns.WriteBytes(ctx, data) |
| 418 | if err != nil { |
| 419 | return err |
| 420 | } |
| 421 | if err = mapEditor.Update(ctx, string(seq.Id), h); err != nil { |
| 422 | return err |
| 423 | } |
| 424 | } |
| 425 | // Assign underlyingMap only after the error check. Flush returns a |
| 426 | // zero AddressMap on failure, which would corrupt the Collection. |
| 427 | flushed, err := mapEditor.Flush(ctx) |
| 428 | if err != nil { |
| 429 | return err |
| 430 | } |
| 431 | pgs.underlyingMap = flushed |
| 432 | clear(pgs.accessedMap) |
| 433 | return nil |
| 434 | } |
| 435 | |
| 436 | // nextValForSequence increments the calling sequence. |
| 437 | func (sequence *Sequence) nextValForSequence() (int64, error) { |
no test coverage detected