Ejemplo n.º 1
0
func writeCgetResponse(w *bufio.Writer, etag uint64, item *ybc.Item, scratchBuf *[]byte) bool {
	var validateTtl, flags uint32
	if err := binaryRead(item, &validateTtl, "validateTtl"); err != nil {
		return false
	}
	if err := binaryRead(item, &flags, "flags"); err != nil {
		return false
	}

	size := item.Available()
	expiration := item.Ttl()
	return writeStr(w, strValue) && writeInt(w, size, scratchBuf) && writeWs(w) &&
		writeUint32(w, flags, scratchBuf) && writeWs(w) &&
		writeExpiration(w, expiration, scratchBuf) && writeWs(w) &&
		writeUint64(w, etag, scratchBuf) && writeWs(w) &&
		writeUint32(w, validateTtl, scratchBuf) && writeCrLf(w) &&
		writeItem(w, item, size)
}
Ejemplo n.º 2
0
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)
	}

}