func updateLocalItem(cache ybc.Cacher, it *ybc.Item, key []byte, casid uint64, flags, validateTtl uint32) { size := it.Available() defer it.Seek(-int64(size), 2) txn := writeItemMetadata(cache, key, size, casid, flags, validateTtl) if txn == nil { return } defer txn.Commit() n, err := txn.ReadFrom(it) if err != nil { log.Fatalf("Unexpected error in SetTxn.ReadFrom(size=%d): [%s]", size, err) } if n != int64(size) { log.Fatalf("Unexpected number of bytes copied in SetTxn.ReadFrom(size=%d): %d", size, n) } }
func updateLocalItem(cache ybc.Cacher, it *ybc.Item, item *Item, etag uint64, validateTtl uint32) { size := it.Available() offset := it.Size() - size defer it.Seek(int64(offset), 0) txn := writeItemMetadata(cache, item.Key, size, it.Ttl(), etag, validateTtl, item.Flags) if txn == nil { return } defer txn.Commit() n, err := txn.ReadFrom(it) if err != nil { log.Fatalf("Unexpected error in SetTxn.ReadFrom(size=%d): [%s]", size, err) } if n != int64(size) { log.Fatalf("Unexpected number of bytes copied in SetTxn.ReadFrom(size=%d): %d", size, n) } }
func checkAndUpdateCasid(item *ybc.Item, casid *uint64) (isModified, ok bool) { casidOld := *casid var buf [casidSize]byte n, err := item.Read(buf[:]) if err != nil { log.Printf("Cannod read casid from item: [%s]", err) return } if n != len(buf) { log.Printf("Unexpected result returned from ybc.Item.Read(): %d. Expected %d", n, len(buf)) return } *casid = binary.LittleEndian.Uint64(buf[:]) if _, err := item.Seek(-casidSize, 1); err != nil { log.Fatalf("Unexpected error returned from ybc.Item.Seek(%d, 1): [%s]", -casidSize, err) } isModified = (casidOld != *casid) ok = true return }