Skip to content

Commit

Permalink
Switch to primitive package
Browse files Browse the repository at this point in the history
  • Loading branch information
tchajed authored and upamanyus committed Jul 25, 2024
1 parent 7191305 commit 79cc60d
Show file tree
Hide file tree
Showing 32 changed files with 115 additions and 110 deletions.
8 changes: 4 additions & 4 deletions bank/bank.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package bank

import (
"github.com/goose-lang/goose/machine"
"github.com/goose-lang/primitive"
"github.com/mit-pdos/gokv/kv"
"github.com/mit-pdos/gokv/lockservice"
"github.com/tchajed/marshal"
Expand Down Expand Up @@ -64,9 +64,9 @@ func (bck *BankClerk) transfer_internal(acc_from string, acc_to string, amount u

func (bck *BankClerk) SimpleTransfer() {
for {
src := machine.RandomUint64()
dst := machine.RandomUint64()
amount := machine.RandomUint64()
src := primitive.RandomUint64()
dst := primitive.RandomUint64()
amount := primitive.RandomUint64()
if src < uint64(len(bck.accts)) && dst < uint64(len(bck.accts)) && src != dst {
bck.transfer_internal(bck.accts[src], bck.accts[dst], amount)
}
Expand Down
4 changes: 2 additions & 2 deletions ctrexample/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import (
"fmt"
"github.com/goose-lang/goose/machine"
"github.com/goose-lang/primitive"
"github.com/mit-pdos/gokv/urpc"
"github.com/tchajed/marshal"
)
Expand All @@ -26,7 +26,7 @@ func main() {
dec := marshal.NewDec(*rep)
v := dec.GetInt()

machine.Assert(v >= localBound)
primitive.Assert(v >= localBound)
localBound = v
fmt.Println("One")
}
Expand Down
6 changes: 3 additions & 3 deletions dmvcc/example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"log"

"github.com/goose-lang/goose/machine"
"github.com/goose-lang/primitive"
"github.com/mit-pdos/gokv/dmvcc/index"
"github.com/mit-pdos/gokv/dmvcc/txn"
"github.com/mit-pdos/gokv/dmvcc/txncoordinator"
Expand All @@ -28,12 +28,12 @@ func main() {
txnCk := txn.Begin(txnMgrHost, txnCoordHost, indexHost)
txnCk.DoTxn(func(t *txn.Clerk) bool {
if len(t.Get(0)) > 0 {
machine.Assert(len(t.Get(1)) > 0)
primitive.Assert(len(t.Get(1)) > 0)
}
log.Printf("Val on txn2: '%s'", t.Get(1))
return true
})
}()

machine.Sleep(uint64(100_000_000))
primitive.Sleep(uint64(100_000_000))
}
6 changes: 3 additions & 3 deletions dmvcc/prophname/g.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package prophname

import "github.com/goose-lang/goose/machine"
import "github.com/goose-lang/primitive"

func Get() machine.ProphId {
return machine.NewProph()
func Get() primitive.ProphId {
return primitive.NewProph()
}
4 changes: 2 additions & 2 deletions dmvcc/txn/clerk.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import (
"github.com/mit-pdos/vmvcc/trusted_proph"

// "github.com/mit-pdos/gokv/grove_ffi"
"github.com/goose-lang/goose/machine"
"github.com/goose-lang/primitive"
)

type Clerk struct {
p machine.ProphId
p primitive.ProphId
tid uint64
writes map[uint64]string
indexCk *index.Clerk
Expand Down
6 changes: 3 additions & 3 deletions dmvcc/txnmgr/server.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package txnmgr

import (
"github.com/goose-lang/goose/machine"
"github.com/goose-lang/primitive"
"sync"
)

type Server struct {
mu *sync.Mutex
p machine.ProphId
p primitive.ProphId
nextTid uint64
}

func MakeServer() *Server {
p := machine.NewProph()
p := primitive.NewProph()
txnMgr := &Server{p: p, nextTid: 1}
txnMgr.mu = new(sync.Mutex)
return txnMgr
Expand Down
8 changes: 4 additions & 4 deletions fencing/config/client.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package config

import (
"github.com/goose-lang/goose/machine"
"github.com/goose-lang/primitive"
"github.com/mit-pdos/gokv/grove_ffi"
"github.com/mit-pdos/gokv/urpc"
"github.com/tchajed/marshal"
Expand All @@ -26,7 +26,7 @@ func (ck *Clerk) HeartbeatThread(epoch uint64) {
// XXX: make this statistically rigorous (e.g. aim for at most x% chance
// of spurious leader failure per hour)
reply_ptr := new([]byte)
machine.Sleep(TIMEOUT_MS * MILLION / 3)
primitive.Sleep(TIMEOUT_MS * MILLION / 3)
err := ck.cl.Call(RPC_HB, args, reply_ptr, 100 /* ms */)
if err != 0 || len(*reply_ptr) != 0 {
break
Expand All @@ -41,7 +41,7 @@ func (ck *Clerk) AcquireEpoch(newFrontend grove_ffi.Address) uint64 {
err := ck.cl.Call(RPC_ACQUIRE_EPOCH, enc.Finish(), reply_ptr, 100 /* ms */)
if err != 0 {
log.Println("config: client failed to run RPC on config server")
machine.Exit(1)
primitive.Exit(1)
}
dec := marshal.NewDec(*reply_ptr)
return dec.GetInt()
Expand All @@ -52,7 +52,7 @@ func (ck *Clerk) Get() uint64 {
err := ck.cl.Call(RPC_GET, make([]byte, 0), reply_ptr, 100 /* ms */)
if err != 0 {
log.Println("config: client failed to run RPC on config server")
machine.Exit(1)
primitive.Exit(1)
}
dec := marshal.NewDec(*reply_ptr)
return dec.GetInt()
Expand Down
10 changes: 5 additions & 5 deletions fencing/config/server.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package config

import (
"github.com/goose-lang/goose/machine"
"github.com/goose-lang/primitive"
"github.com/mit-pdos/gokv/grove_ffi"
"github.com/mit-pdos/gokv/urpc"
"github.com/tchajed/marshal"
Expand Down Expand Up @@ -33,7 +33,7 @@ func (s *Server) AcquireEpoch(newFrontend grove_ffi.Address) uint64 {
s.data = newFrontend
s.currentEpoch += 1

now := machine.TimeNow()
now := primitive.TimeNow()
s.heartbeatExpiration = now + TIMEOUT_MS*MILLION

ret := s.currentEpoch
Expand All @@ -58,12 +58,12 @@ func (s *Server) HeartbeatListener() {

// loops until the heartbeat expiration time is passed
for {
now := machine.TimeNow()
now := primitive.TimeNow()
s.mu.Lock()
if now < s.heartbeatExpiration {
delay := s.heartbeatExpiration - now
s.mu.Unlock()
machine.Sleep(delay)
primitive.Sleep(delay)
} else {
s.currHolderActive = false
s.currHolderActive_cond.Signal()
Expand All @@ -82,7 +82,7 @@ func (s *Server) Heartbeat(epoch uint64) bool {
s.mu.Lock()
var ret bool = false
if s.currentEpoch == epoch {
now := machine.TimeNow()
now := primitive.TimeNow()
s.heartbeatExpiration = now + TIMEOUT_MS
ret = true
}
Expand Down
14 changes: 7 additions & 7 deletions fencing/ctr/client.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ctr

import (
"github.com/goose-lang/goose/machine"
"github.com/goose-lang/primitive"
"github.com/mit-pdos/gokv/erpc"
"github.com/mit-pdos/gokv/grove_ffi"
"github.com/mit-pdos/gokv/urpc"
Expand All @@ -24,19 +24,19 @@ func (c *Clerk) Get(epoch uint64) uint64 {
enc := marshal.NewEnc(8)
enc.PutInt(epoch)
req := enc.Finish()
valProph := machine.NewProph()
valProph := primitive.NewProph()

reply_ptr := new([]byte)
err := c.cl.Call(RPC_GET, req, reply_ptr, 100 /* ms */)
if err != 0 {
log.Println("ctr: urpc get call failed/timed out")
machine.Exit(1)
primitive.Exit(1)
}
r := DecGetReply(*reply_ptr)

if r.err != ENone {
log.Println("ctr: get() stale epoch number")
machine.Exit(1)
primitive.Exit(1)
}
valProph.ResolveU64(r.val)
return r.val
Expand All @@ -53,15 +53,15 @@ func (c *Clerk) Put(v uint64, epoch uint64) {
err := c.cl.Call(RPC_PUT, req, reply_ptr, 100 /* ms */)
if err != 0 {
log.Println("ctr: urpc put call failed/timed out")
machine.Exit(1)
primitive.Exit(1)
}

dec := marshal.NewDec(*reply_ptr)
epochErr := dec.GetInt()

if epochErr != ENone {
log.Println("ctr: get() stale epoch number")
machine.Exit(1)
primitive.Exit(1)
}
return
}
Expand All @@ -75,7 +75,7 @@ func MakeClerk(host grove_ffi.Address) *Clerk {
if err != 0 {
// panic("ctr: urpc call failed/timed out")
log.Println("ctr: urpc getcid call failed/timed out")
machine.Exit(1)
primitive.Exit(1)
}
ck.e = erpc.MakeClient(marshal.NewDec(*reply_ptr).GetInt())

Expand Down
4 changes: 2 additions & 2 deletions fencing/ctr/server.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ctr

import (
"github.com/goose-lang/goose/machine"
"github.com/goose-lang/primitive"
"github.com/mit-pdos/gokv/erpc"
"github.com/mit-pdos/gokv/grove_ffi"
"github.com/mit-pdos/gokv/urpc"
Expand Down Expand Up @@ -44,7 +44,7 @@ func (s *Server) Get(epoch uint64, reply *GetReply) {
s.lastEpoch = epoch

reply.val = s.v
machine.Linearize()
primitive.Linearize()
s.mu.Unlock()
return
}
Expand Down
4 changes: 2 additions & 2 deletions fencing/loopclient/loopclient.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package loopclient

import (
"github.com/goose-lang/goose/machine"
"github.com/goose-lang/primitive"
"github.com/mit-pdos/gokv/fencing/client"
"github.com/mit-pdos/gokv/grove_ffi"
"log"
Expand All @@ -14,7 +14,7 @@ func LoopOnKey(key uint64, config grove_ffi.Address) {
var lowerBound uint64 = ck.FetchAndIncrement(key)
for {
v := ck.FetchAndIncrement(key)
machine.Assert(v > lowerBound)
primitive.Assert(v > lowerBound)
if v%1000 == 0 {
log.Printf("reached %d >= %d", key, v)
}
Expand Down
11 changes: 7 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ go 1.22

require (
github.com/felixge/fgprof v0.9.4
github.com/goose-lang/goose v0.6.2
github.com/goose-lang/std v0.3.3
github.com/goose-lang/primitive v0.1.0
github.com/goose-lang/std v0.4.1
github.com/mit-pdos/vmvcc v0.2.0
github.com/tchajed/marshal v0.6.1
github.com/tchajed/marshal v0.6.2
golang.org/x/text v0.16.0
)

require github.com/google/pprof v0.0.0-20240711041743-f6c9dda6c6da // indirect
require (
github.com/google/pprof v0.0.0-20240711041743-f6c9dda6c6da // indirect
github.com/goose-lang/goose v0.7.1 // indirect
)
14 changes: 8 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ github.com/gobwas/ws v1.2.1/go.mod h1:hRKAFb8wOxFROYNsT1bqfWnhX+b5MFeJM9r2ZSwg/K
github.com/google/pprof v0.0.0-20240227163752-401108e1b7e7/go.mod h1:czg5+yv1E0ZGTi6S6vVK1mke0fV+FaUhNGcd6VRS9Ik=
github.com/google/pprof v0.0.0-20240711041743-f6c9dda6c6da h1:xRmpO92tb8y+Z85iUOMOicpCfaYcv7o3Cg3wKrIpg8g=
github.com/google/pprof v0.0.0-20240711041743-f6c9dda6c6da/go.mod h1:K1liHPHnj73Fdn/EKuT8nrFqBihUSKXoLYU0BuatOYo=
github.com/goose-lang/goose v0.6.2 h1:Z39QWk7UowzisFL9rnLd4/C+Cg0VF8oPvqOUE+aGB+w=
github.com/goose-lang/goose v0.6.2/go.mod h1:jSP/O+LNLVD4P4itkfh8Ly05NdJ1NYbLjYWkoZs86WU=
github.com/goose-lang/std v0.3.3 h1:UjxgenvQFlWKpxqJjbIlbaXsqwP0Sh+FzY63sF+4NkY=
github.com/goose-lang/std v0.3.3/go.mod h1:9sR9tiZzSzUGh5erxPX3gbWpVZ/4Kjs2C2zGfKUqoNk=
github.com/goose-lang/goose v0.7.1 h1:o2XGywsaQgQmNyMsPDT4dwFBDAxeAflFQo+zGuF9OGw=
github.com/goose-lang/goose v0.7.1/go.mod h1:Yf+T8Mii3tuRE+cKuN80JZlDkKdRIOm9+4k2kj0rBew=
github.com/goose-lang/primitive v0.1.0 h1:JReOdFzUdGD7f8nWTC/uOlNpBdVFU4q8HzMSgn8edaY=
github.com/goose-lang/primitive v0.1.0/go.mod h1:sDE72zVH81ASwPXc1m9OgSfaaY0aZHu4Ty19FgONpOc=
github.com/goose-lang/std v0.4.1 h1:ezoEYbvePtF2TD8vuUUTt5lO893CA6QTgoBX896F8BU=
github.com/goose-lang/std v0.4.1/go.mod h1:bnKHDHwU0lHf99eMI5PVM77UweRyu6qgM/h43qGBRto=
github.com/ianlancetaylor/demangle v0.0.0-20230524184225-eabc099b10ab/go.mod h1:gx7rwoVhcfuVKG5uya9Hs3Sxj7EIvldVofAWIUtGouw=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/ledongthuc/pdf v0.0.0-20220302134840-0c2507a12d80/go.mod h1:imJHygn/1yfhB7XSJJKlFZKl/J+dCPAknuiaGOshXAs=
Expand All @@ -34,8 +36,8 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/tchajed/marshal v0.6.1 h1:fSpd/Q/Fxc4Pn2BqqmBQyUUKGqRyZ4jdu3sQqwa2FW0=
github.com/tchajed/marshal v0.6.1/go.mod h1:bpCjDLDucqTM51woyzbZP5ku3hT4TORx7YGhyWSUpA4=
github.com/tchajed/marshal v0.6.2 h1:DSrylV2Sc47G4RJG2KSOp7HrA76Hd5Bj2WVGtXB/bCw=
github.com/tchajed/marshal v0.6.2/go.mod h1:nY/NmbQidx2CdBY4Y8NdUTnDXgWmhQ6Hg1es+PnxBx8=
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
Expand Down
8 changes: 4 additions & 4 deletions memkv/bank/bank.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package bank

import (
"github.com/goose-lang/goose/machine"
"github.com/goose-lang/primitive"
"github.com/goose-lang/std"
"github.com/mit-pdos/gokv/connman"
"github.com/mit-pdos/gokv/memkv"
Expand Down Expand Up @@ -49,9 +49,9 @@ func (bck *BankClerk) transfer_internal(acc_from uint64, acc_to uint64, amount u

func (bck *BankClerk) SimpleTransfer() {
for {
src := machine.RandomUint64()
dst := machine.RandomUint64()
amount := machine.RandomUint64()
src := primitive.RandomUint64()
dst := primitive.RandomUint64()
amount := primitive.RandomUint64()
if src < uint64(len(bck.accts)) && dst < uint64(len(bck.accts)) && src != dst {
bck.transfer_internal(bck.accts[src], bck.accts[dst], amount)
}
Expand Down
6 changes: 3 additions & 3 deletions minlease/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package minlease
import (
"sync"

"github.com/goose-lang/goose/machine"
"github.com/goose-lang/primitive"
"github.com/goose-lang/std"
"github.com/mit-pdos/gokv/grove_ffi"
)
Expand Down Expand Up @@ -65,15 +65,15 @@ func client(s *Server) {
if l > s.leaseExpiration {
break
}
machine.Sleep(s.leaseExpiration - l)
primitive.Sleep(s.leaseExpiration - l)
}

// now the client has the lease
v := s.Get()
newv := std.SumAssumeNoOverflow(v, 1)
s.Put(newv)
v2 := s.Get()
machine.Assert(v2 == newv)
primitive.Assert(v2 == newv)
}

func main() {
Expand Down
Loading

0 comments on commit 79cc60d

Please sign in to comment.