Skip to content

Commit

Permalink
update to use value-based grackle
Browse files Browse the repository at this point in the history
  • Loading branch information
mjschwenne committed Jan 9, 2025
1 parent 80fb0f2 commit 4115e26
Show file tree
Hide file tree
Showing 18 changed files with 172 additions and 122 deletions.
8 changes: 4 additions & 4 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
src = pkgs.fetchFromGitHub {
owner = "goose-lang";
repo = "goose";
rev = "8d13c771b9a80957089f7c5b0ee2ccf58e5eb06f";
sha256 = "1fbqs75ya4as3my2knkaq4m0crdh3n004grw5g5iczvb5h5k06lz";
rev = "a4f2f84193d34f56dd84fc623adc43a6441da1eb";
sha256 = "1b1dfa1qsv2h7hy5x20zhic2npr5gz1zp76m1lab4v490adxj2rx";
};
vendorHash = "sha256-HCJ8v3TSv4UrkOsRuENWVz5Z7zQ1UsOygx0Mo7MELzY=";
};
Expand All @@ -27,8 +27,8 @@
src = pkgs.fetchFromGitHub {
owner = "mjschwenne";
repo = "grackle";
rev = "ee8a2fbea1c4cef22336a2a1760de5c0ba4a9c72";
sha256 = "08drdzjgj3006l3hxyiqfvm7y2i8m6hmsc108rj6i1w22kd0pv4g";
rev = "101412356cdfbcad78f8aaa724101312928c4978";
sha256 = "06zf2bvrbbjhgrd6994h3wcaml7m83m6f9r61pj7y09xq9nw10br";
};
vendorHash = "sha256-Wk2v0HSAkrzxHJvCfbw6xOn0OQ1xukvYjDxk3c2LmH8=";
checkPhase = false;
Expand Down
8 changes: 4 additions & 4 deletions tutorial/kvservice/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ func (ck *Clerk) Put(key string, val string) {
for {
// TODO: allocate these once, outside the loop. Waiting to do this until
// heap has dfrac for convenience.
args := &put_gk.S{
args := put_gk.S{
OpId: opId,
Key: key,
Val: val,
Value: val,
}
if ck.rpcCl.putRpc(args) == urpc.ErrNone {
break
Expand All @@ -63,7 +63,7 @@ func (ck *Clerk) ConditionalPut(key string, expectedVal string, newVal string) b

var ret bool
for {
args := &conditionalput_gk.S{
args := conditionalput_gk.S{
OpId: opId,
Key: key,
ExpectedVal: expectedVal,
Expand Down Expand Up @@ -94,7 +94,7 @@ func (ck *Clerk) Get(key string) string {

var ret string
for {
args := &get_gk.S{
args := get_gk.S{
OpId: opId,
Key: key,
}
Expand Down
33 changes: 21 additions & 12 deletions tutorial/kvservice/conditionalput_gk/conditionalput_gk.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
//--------------------------------------
// This file is autogenerated by grackle
// DO NOT MANUALLY EDIT THIS FILE
//--------------------------------------

package conditionalput_gk

import (
Expand All @@ -11,11 +16,7 @@ type S struct {
NewVal string
}

func (c *S) approxSize() uint64 {
return 0
}

func Marshal(c *S, prefix []byte) []byte {
func Marshal(c S, prefix []byte) []byte {
var enc = prefix

enc = marshal.WriteInt(enc, c.OpId)
Expand All @@ -32,26 +33,34 @@ func Marshal(c *S, prefix []byte) []byte {
return enc
}

func Unmarshal(s []byte) (*S, []byte) {
c := new(S)
func Unmarshal(s []byte) (S, []byte) {
var enc = s // Needed for goose compatibility
var opId uint64
var key string
var expectedVal string
var newVal string

c.OpId, enc = marshal.ReadInt(enc)
opId, enc = marshal.ReadInt(enc)
var keyLen uint64
var keyBytes []byte
keyLen, enc = marshal.ReadInt(enc)
keyBytes, enc = marshal.ReadBytesCopy(enc, keyLen)
c.Key = string(keyBytes)
key = string(keyBytes)
var expectedValLen uint64
var expectedValBytes []byte
expectedValLen, enc = marshal.ReadInt(enc)
expectedValBytes, enc = marshal.ReadBytesCopy(enc, expectedValLen)
c.ExpectedVal = string(expectedValBytes)
expectedVal = string(expectedValBytes)
var newValLen uint64
var newValBytes []byte
newValLen, enc = marshal.ReadInt(enc)
newValBytes, enc = marshal.ReadBytesCopy(enc, newValLen)
c.NewVal = string(newValBytes)
newVal = string(newValBytes)

return c, enc
return S{
OpId: opId,
Key: key,
ExpectedVal: expectedVal,
NewVal: newVal,
}, enc
}
25 changes: 15 additions & 10 deletions tutorial/kvservice/get_gk/get_gk.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
//--------------------------------------
// This file is autogenerated by grackle
// DO NOT MANUALLY EDIT THIS FILE
//--------------------------------------

package get_gk

import (
Expand All @@ -9,11 +14,7 @@ type S struct {
Key string
}

func (g *S) approxSize() uint64 {
return 0
}

func Marshal(g *S, prefix []byte) []byte {
func Marshal(g S, prefix []byte) []byte {
var enc = prefix

enc = marshal.WriteInt(enc, g.OpId)
Expand All @@ -24,16 +25,20 @@ func Marshal(g *S, prefix []byte) []byte {
return enc
}

func Unmarshal(s []byte) (*S, []byte) {
g := new(S)
func Unmarshal(s []byte) (S, []byte) {
var enc = s // Needed for goose compatibility
var opId uint64
var key string

g.OpId, enc = marshal.ReadInt(enc)
opId, enc = marshal.ReadInt(enc)
var keyLen uint64
var keyBytes []byte
keyLen, enc = marshal.ReadInt(enc)
keyBytes, enc = marshal.ReadBytesCopy(enc, keyLen)
g.Key = string(keyBytes)
key = string(keyBytes)

return g, enc
return S{
OpId: opId,
Key: key,
}, enc
}
2 changes: 1 addition & 1 deletion tutorial/kvservice/kvservice.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ syntax = "proto3";
message put {
uint64 opId = 1;
string key = 2;
string val = 3;
string value = 3;
}

message conditionalPut {
Expand Down
6 changes: 3 additions & 3 deletions tutorial/kvservice/kvservice_rpc.gb.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (cl *Client) getFreshNumRpc() (uint64, Error) {
return 0, err
}

func (cl *Client) putRpc(args *put_gk.S) Error {
func (cl *Client) putRpc(args put_gk.S) Error {
var reply []byte
err := cl.cl.Call(rpcIdPut, put_gk.Marshal(args, make([]byte, 0)), &reply, 100)
if err == urpc.ErrNone {
Expand All @@ -39,7 +39,7 @@ func (cl *Client) putRpc(args *put_gk.S) Error {
return err
}

func (cl *Client) conditionalPutRpc(args *conditionalput_gk.S) (string, Error) {
func (cl *Client) conditionalPutRpc(args conditionalput_gk.S) (string, Error) {
var reply []byte
err := cl.cl.Call(rpcIdConditionalPut, conditionalput_gk.Marshal(args, make([]byte, 0)), &reply, 100)
if err == urpc.ErrNone {
Expand All @@ -48,7 +48,7 @@ func (cl *Client) conditionalPutRpc(args *conditionalput_gk.S) (string, Error) {
return "", err
}

func (cl *Client) getRpc(args *get_gk.S) (string, Error) {
func (cl *Client) getRpc(args get_gk.S) (string, Error) {
var reply []byte
err := cl.cl.Call(rpcIdGet, get_gk.Marshal(args, make([]byte, 0)), &reply, 100)
if err == urpc.ErrNone {
Expand Down
51 changes: 29 additions & 22 deletions tutorial/kvservice/put_gk/put_gk.go
Original file line number Diff line number Diff line change
@@ -1,48 +1,55 @@
//--------------------------------------
// This file is autogenerated by grackle
// DO NOT MANUALLY EDIT THIS FILE
//--------------------------------------

package put_gk

import (
"github.com/tchajed/marshal"
)

type S struct {
OpId uint64
Key string
Val string
}

func (p *S) approxSize() uint64 {
return 0
OpId uint64
Key string
Value string
}

func Marshal(p *S, prefix []byte) []byte {
func Marshal(p S, prefix []byte) []byte {
var enc = prefix

enc = marshal.WriteInt(enc, p.OpId)
keyBytes := []byte(p.Key)
enc = marshal.WriteInt(enc, uint64(len(keyBytes)))
enc = marshal.WriteBytes(enc, keyBytes)
valBytes := []byte(p.Val)
enc = marshal.WriteInt(enc, uint64(len(valBytes)))
enc = marshal.WriteBytes(enc, valBytes)
valueBytes := []byte(p.Value)
enc = marshal.WriteInt(enc, uint64(len(valueBytes)))
enc = marshal.WriteBytes(enc, valueBytes)

return enc
}

func Unmarshal(s []byte) (*S, []byte) {
p := new(S)
func Unmarshal(s []byte) (S, []byte) {
var enc = s // Needed for goose compatibility
var opId uint64
var key string
var value string

p.OpId, enc = marshal.ReadInt(enc)
opId, enc = marshal.ReadInt(enc)
var keyLen uint64
var keyBytes []byte
keyLen, enc = marshal.ReadInt(enc)
keyBytes, enc = marshal.ReadBytesCopy(enc, keyLen)
p.Key = string(keyBytes)
var valLen uint64
var valBytes []byte
valLen, enc = marshal.ReadInt(enc)
valBytes, enc = marshal.ReadBytesCopy(enc, valLen)
p.Val = string(valBytes)

return p, enc
key = string(keyBytes)
var valueLen uint64
var valueBytes []byte
valueLen, enc = marshal.ReadInt(enc)
valueBytes, enc = marshal.ReadBytesCopy(enc, valueLen)
value = string(valueBytes)

return S{
OpId: opId,
Key: key,
Value: value,
}, enc
}
8 changes: 4 additions & 4 deletions tutorial/kvservice/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ func (s *Server) getFreshNum() uint64 {
return n
}

func (s *Server) put(args *put_gk.S) {
func (s *Server) put(args put_gk.S) {
s.mu.Lock()
_, ok := s.lastReplies[args.OpId]
if ok {
s.mu.Unlock()
return
}
s.kvs[args.Key] = args.Val
s.kvs[args.Key] = args.Value
s.lastReplies[args.OpId] = ""
s.mu.Unlock()
}

func (s *Server) conditionalPut(args *conditionalput_gk.S) string {
func (s *Server) conditionalPut(args conditionalput_gk.S) string {
s.mu.Lock()
ret, ok := s.lastReplies[args.OpId]
if ok {
Expand All @@ -54,7 +54,7 @@ func (s *Server) conditionalPut(args *conditionalput_gk.S) string {
return ret2
}

func (s *Server) get(args *get_gk.S) string {
func (s *Server) get(args get_gk.S) string {
s.mu.Lock()
ret, ok := s.lastReplies[args.OpId]
if ok {
Expand Down
4 changes: 2 additions & 2 deletions tutorial/lockservice/1_lock_rpc.gb.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (cl *Client) getFreshNum() (uint64, Error) {

func (cl *Client) tryAcquire(id uint64) (uint64, Error) {
var reply []byte
args := lockrequest_gk.Marshal(&lockrequest_gk.S{Id: id}, []byte{})
args := lockrequest_gk.Marshal(lockrequest_gk.S{Id: id}, []byte{})
err := cl.cl.Call(RPC_TRY_ACQUIRE, args, &reply, 100)
if err == urpc.ErrNone {
return DecodeUint64(reply), err
Expand All @@ -40,7 +40,7 @@ func (cl *Client) tryAcquire(id uint64) (uint64, Error) {

func (cl *Client) release(id uint64) Error {
var reply []byte
args := lockrequest_gk.Marshal(&lockrequest_gk.S{Id: id}, []byte{})
args := lockrequest_gk.Marshal(lockrequest_gk.S{Id: id}, []byte{})
return cl.cl.Call(RPC_RELEASE, args, &reply, 100)
}

Expand Down
21 changes: 12 additions & 9 deletions tutorial/lockservice/lockrequest_gk/lockrequest_gk.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
//--------------------------------------
// This file is autogenerated by grackle
// DO NOT MANUALLY EDIT THIS FILE
//--------------------------------------

package lockrequest_gk

import (
Expand All @@ -8,23 +13,21 @@ type S struct {
Id uint64
}

func (l *S) approxSize() uint64 {
return 0
}

func Marshal(l *S, prefix []byte) []byte {
func Marshal(l S, prefix []byte) []byte {
var enc = prefix

enc = marshal.WriteInt(enc, l.Id)

return enc
}

func Unmarshal(s []byte) (*S, []byte) {
l := new(S)
func Unmarshal(s []byte) (S, []byte) {
var enc = s // Needed for goose compatibility
var id uint64

l.Id, enc = marshal.ReadInt(enc)
id, enc = marshal.ReadInt(enc)

return l, enc
return S{
Id: id,
}, enc
}
2 changes: 1 addition & 1 deletion tutorial/objectstore/chunk/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type ClerkPool struct {
}

func (ck *ClerkPool) WriteChunk(addr grove_ffi.Address, args writechunk_gk.S) {
req := writechunk_gk.Marshal(&args, make([]byte, 0))
req := writechunk_gk.Marshal(args, make([]byte, 0))
reply := new([]byte)
ck.cm.CallAtLeastOnce(addr, WriteChunkId, req, reply, 100 /*ms*/)
}
Expand Down
2 changes: 1 addition & 1 deletion tutorial/objectstore/chunk/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func StartServer(me grove_ffi.Address, dir_addr grove_ffi.Address) {
handlers := make(map[uint64]func([]byte, *[]byte))
handlers[WriteChunkId] = func(req []byte, reply *[]byte) {
args, _ := writechunk_gk.Unmarshal(req)
s.WriteChunk(*args)
s.WriteChunk(args)
*reply = make([]byte, 0) // TODO: is this needed?
}
handlers[GetChunkId] = func(req []byte, reply *[]byte) {
Expand Down
Loading

0 comments on commit 4115e26

Please sign in to comment.