From cc2f697fff4c3b79438c703cbac6bdfd0cb3204e Mon Sep 17 00:00:00 2001 From: Yun-Sheng Chang Date: Sat, 20 Jul 2024 14:42:45 -0400 Subject: [PATCH] Remove examples unable to build --- examples/deprecated/counter.go | 106 ---------------------------- examples/deprecated/rsvkey.go | 52 -------------- tests/tid-collision/main.go | 124 --------------------------------- 3 files changed, 282 deletions(-) delete mode 100644 examples/deprecated/counter.go delete mode 100644 examples/deprecated/rsvkey.go delete mode 100644 tests/tid-collision/main.go diff --git a/examples/deprecated/counter.go b/examples/deprecated/counter.go deleted file mode 100644 index 156b019..0000000 --- a/examples/deprecated/counter.go +++ /dev/null @@ -1,106 +0,0 @@ -//go:build ignore - -package examples - -import ( - "github.com/goose-lang/primitive" - "github.com/mit-pdos/vmvcc/txn" -) - -func fetch(txn *txn.Txn, p *uint64) bool { - v, _ := txn.Read(0) - *p = v - - return true -} - -func Fetch(t *txn.Txn) uint64 { - var n uint64 - body := func(txn *txn.Txn) bool { - return fetch(txn, &n) - } - t.Run(body) - return n -} - -func increment(txn *txn.Txn, p *uint64) bool { - v, _ := txn.Read(0) - *p = v - if v == 18446744073709551615 { - return false - } - txn.Write(0, v+1) - - return true -} - -func Increment(t *txn.Txn) (uint64, bool) { - var n uint64 - body := func(txn *txn.Txn) bool { - return increment(txn, &n) - } - ok := t.Run(body) - return n, ok -} - -func decrement(txn *txn.Txn, p *uint64) bool { - v, _ := txn.Read(0) - *p = v - if v == 0 { - return false - } - txn.Write(0, v-1) - return true -} - -func Decrement(t *txn.Txn) (uint64, bool) { - var n uint64 - body := func(txn *txn.Txn) bool { - return decrement(txn, &n) - } - ok := t.Run(body) - return n, ok -} - -func InitializeCounterData(mgr *txn.TxnMgr) { - // Initialize key 0 to some value - body := func(txn *txn.Txn) bool { - txn.Write(0, 0) - return true - } - // We wrap this transaction in a loop because the spec says it might fail. - // However, init methods should never fail as there are no contending txns. - // A better way is to have init RPs (for `tuple` and `table`) and specs - // that always succeed given those init RPs. These init RPs are only - // available at init time, and updated to regular RPs before they are - // sealed in some invariants. - t := mgr.New() - for !t.Run(body) { - } -} - -func InitCounter() *txn.TxnMgr { - mgr := txn.MkTxnMgr() - InitializeCounterData(mgr) - return mgr -} - -func CallIncrement(mgr *txn.TxnMgr) { - txn := mgr.New() - Increment(txn) -} - -func CallIncrementFetch(mgr *txn.TxnMgr) { - txn := mgr.New() - n1, ok1 := Increment(txn) - if !ok1 { - return - } - n2 := Fetch(txn) - primitive.Assert(n1 < n2) -} - -func CallDecrement(mgr *txn.TxnMgr) { - txn := mgr.New() - Decrement(txn) -} diff --git a/examples/deprecated/rsvkey.go b/examples/deprecated/rsvkey.go deleted file mode 100644 index 15219e4..0000000 --- a/examples/deprecated/rsvkey.go +++ /dev/null @@ -1,52 +0,0 @@ -//go:build ignore - -package examples - -import ( - "github.com/mit-pdos/vmvcc/txn" -) - -func WriteReservedKeySeq(txn *txn.Txn, v uint64) bool { - txn.Write(0, v) - return true -} - -func WriteReservedKey(t *txn.Txn, v uint64) bool { - body := func(txn *txn.Txn) bool { - return WriteReservedKeySeq(txn, v) - } - return t.Run(body) -} - -func WriteFreeKeySeq(txn *txn.Txn, v uint64) bool { - txn.Write(1, v) - return true -} - -func WriteFreeKey(t *txn.Txn, v uint64) bool { - body := func(txn *txn.Txn) bool { - return WriteFreeKeySeq(txn, v) - } - return t.Run(body) -} - -func InitializeData(mgr *txn.TxnMgr) { -} - -func InitExample() *txn.TxnMgr { - mgr := txn.MkTxnMgr() - InitializeData(mgr) - return mgr -} - -func WriteReservedKeyExample(mgr *txn.TxnMgr, v uint64) bool { - txn := mgr.New() - ok := WriteReservedKey(txn, v) - return ok -} - -func WriteFreeKeyExample(mgr *txn.TxnMgr, v uint64) bool { - txn := mgr.New() - ok := WriteFreeKey(txn, v) - return ok -} diff --git a/tests/tid-collision/main.go b/tests/tid-collision/main.go deleted file mode 100644 index e040630..0000000 --- a/tests/tid-collision/main.go +++ /dev/null @@ -1,124 +0,0 @@ -//go:build ignore - -// This test intends to test "how frequent timestamps collide if without our -// technique to make it unique". Comment out every line in tid.go except L13 -// for comparison. -package main - -import ( - "fmt" - "github.com/goose-lang/primitive" - "github.com/mit-pdos/vmvcc/txn" - "strconv" - "sync" - "time" -) - -// XXX: need to use many keys to get observably bad behavior from duplicate -// TIDs, because with one key, if there are two transactions using the same tid, -// one of them is likely to end up aborting because wrbuf.OpenTuples doesn't -// retry in case tuple.Own() returns RET_RETRY. - -const nkeys = 16 - -func doIncr(txn *txn.Txn) bool { - var m uint64 - - for i := 0; i < nkeys; i += 1 { - xStr, _ := txn.Read(uint64(i)) - x, err := strconv.ParseUint(xStr, 10, 64) - if err != nil { - panic(err) - } - if x > m { - m = x - } - } - - randKey := primitive.RandomUint64() % nkeys - txn.Write(randKey, strconv.FormatUint(m+1, 10)) - return true -} - -func incrThread(db *txn.TxnMgr) uint64 { - txn := db.New() - numIncrs := uint64(0) - for i := 0; i < 1_000_000; i += 1 { - committed := txn.Run(doIncr) - if committed { - numIncrs += 1 - } - } - return numIncrs -} - -func putZero(db *txn.TxnMgr) int { - t := db.New() - v := new(int) - - committed := t.Run(func(t *txn.Txn) bool { - for i := 0; i < nkeys; i += 1 { - t.Write(uint64(i), "0") - } - return true - }) - if !committed { - panic("put aborted") - } - - return *v -} - -func getValue(db *txn.TxnMgr) uint64 { - t := db.New() - v := new(uint64) - - committed := t.Run(func(t *txn.Txn) bool { - var m uint64 - for i := 0; i < nkeys; i += 1 { - xStr, _ := t.Read(uint64(i)) - x, err := strconv.ParseUint(xStr, 10, 64) - if err != nil { - panic(err) - } - if x > m { - m = x - } - } - *v = m - return true - }) - - if !committed { - panic("read aborted") - } - - return *v -} - -func main() { - n := 8 - numIncrss := make([]uint64, n) - db := txn.MkTxnMgr() - db.ActivateGC() - - putZero(db) - time.Sleep(10 * time.Millisecond) - - wg := new(sync.WaitGroup) - wg.Add(n) - for i, _ := range numIncrss { - i := i - go func() { - numIncrss[i] = incrThread(db) - wg.Done() - }() - } - - wg.Wait() - var s uint64 - for _, numIncrs := range numIncrss { - s += numIncrs - } - fmt.Printf("numIncrs = %d, val = %d\n", s, getValue(db)) -}