Exemple #1
0
// Calls rand 4 times
func (b *Buy) MakeOne(w int, local_seed *uint32, sp uint32, txn *ddtxn.Query) {
	var bidder int
	var product int
	if *partition {
		rnd := ddtxn.RandN(local_seed, sp/8)
		lb := int(rnd)
		bidder = lb + w*int(sp)
	} else {
		bidder = int(ddtxn.RandN(local_seed, uint32(b.nbidders)))
	}
	x := int(ddtxn.RandN(local_seed, 100))
	if b.zipfd > 0 {
		product = int(b.z[w].Uint64())
	} else {
		product = int(ddtxn.RandN(local_seed, uint32(b.nproducts)))
	}
	if x < b.read_rate {
		if x > b.ncontended_rate {
			// Contended read; use Zipfian distribution or np
			txn.K1 = ddtxn.UserKey(uint64(bidder))
			txn.K2 = ddtxn.ProductKey(product)
		} else {
			// (Hopefully) uncontended read.  Random product.
			product = int(ddtxn.RandN(local_seed, uint32(b.nbidders)))
			txn.K1 = ddtxn.UserKey(uint64(bidder))
			txn.K2 = ddtxn.ProductKey(product)
		}
		txn.TXN = ddtxn.D_READ_TWO
	} else {
		amt := int32(ddtxn.RandN(local_seed, 10))
		txn.K1 = ddtxn.UserKey(uint64(bidder))
		txn.K2 = ddtxn.ProductKey(product)
		txn.A = amt
		txn.TXN = ddtxn.D_BUY
	}
}
Exemple #2
0
func (b *Rubis) MakeOne(w int, local_seed *uint32, txn *ddtxn.Query) {
	x := float64(ddtxn.RandN(local_seed, 100))
	if x < b.rates[0] {
		txn.TXN = ddtxn.RUBIS_BID
		//bidder := b.users[int(ddtxn.RandN(local_seed, b.sp))+w*int(b.sp)]
		bidder := b.users[int(ddtxn.RandN(local_seed, uint32(b.nbidders)))]
		//product := b.products[ddtxn.RandN(local_seed, uint32(b.nproducts))]
		var x uint32
		if b.zipfd > 0 {
			x = uint32(b.zip[w].Uint64())
		} else {
			x = ddtxn.RandN(local_seed, uint32(b.nproducts))
		}
		product := b.products[x]
		txn.U1 = uint64(bidder)
		if product == 0 {
			log.Fatalf("store bid ID 0? %v %v", x, b.products[x])
		}
		txn.U2 = uint64(product)
		//txn.U3 = uint64(ddtxn.RandN(local_seed, 10))
		txn.U3 = uint64(time.Now().UnixNano()) & 0x000efff
	} else if x < b.rates[1] {
		txn.TXN = ddtxn.RUBIS_VIEWBIDHIST
		x := ddtxn.RandN(local_seed, uint32(b.nproducts))
		product := b.products[x]
		if product == 0 {
			log.Fatalf("view bid hist ID 0? %v %v", x, b.products[x])
		}
		txn.U1 = uint64(product)
	} else if x < b.rates[2] {
		txn.TXN = ddtxn.RUBIS_BUYNOW
		//bidder := b.users[int(ddtxn.RandN(local_seed, b.sp))+w*int(b.sp)]
		bidder := b.users[int(ddtxn.RandN(local_seed, uint32(b.nbidders)))]
		x := ddtxn.RandN(local_seed, uint32(b.nproducts))
		product := b.products[x]
		if product == 0 {
			log.Fatalf("buy now ID 0? %v %v", x, b.products[x])
		}
		txn.U1 = uint64(bidder)
		txn.U2 = uint64(product)
		txn.A = int32(ddtxn.RandN(local_seed, 10))
	} else if x < b.rates[3] {
		txn.TXN = ddtxn.RUBIS_COMMENT
		//		u1 := b.users[int(ddtxn.RandN(local_seed, b.sp))+w*int(b.sp)]
		u1 := b.users[int(ddtxn.RandN(local_seed, uint32(b.nbidders)))]
		//		u2 := b.users[int(ddtxn.RandN(local_seed, b.sp))+w*int(b.sp)]
		u2 := b.users[int(ddtxn.RandN(local_seed, uint32(b.nbidders)))]
		x := ddtxn.RandN(local_seed, uint32(b.nproducts))
		product := b.products[x]
		if product == 0 {
			log.Fatalf("comment ID 0? %v %v", x, b.products[x])
		}
		txn.U1 = uint64(u1)
		txn.U2 = uint64(u2)
		txn.U3 = uint64(product)
		txn.S1 = "xxxx"
		txn.U4 = 1
	} else if x < b.rates[4] {
		txn.TXN = ddtxn.RUBIS_NEWITEM
		//		bidder := b.users[int(ddtxn.RandN(local_seed, b.sp))+w*int(b.sp)]
		bidder := b.users[int(ddtxn.RandN(local_seed, uint32(b.nbidders)))]
		amt := uint64(ddtxn.RandN(local_seed, 10))
		txn.U1 = uint64(bidder)
		txn.S1 = "yyyy"
		txn.S2 = "zzzz"
		txn.U2 = amt
		txn.U3 = amt
		txn.U4 = amt
		txn.U5 = 1
		txn.U6 = 1
		txn.U7 = uint64(ddtxn.RandN(local_seed, uint32(ddtxn.NUM_CATEGORIES)))
	} else if x < b.rates[5] {
		txn.TXN = ddtxn.RUBIS_PUTBID
		x := ddtxn.RandN(local_seed, uint32(b.nproducts))
		product := b.products[x]
		if product == 0 {
			log.Fatalf("put bid ID 0? %v %v", x, b.products[x])
		}
		txn.U1 = uint64(product)
	} else if x < b.rates[6] {
		txn.TXN = ddtxn.RUBIS_PUTCOMMENT
		x := ddtxn.RandN(local_seed, uint32(b.nproducts))
		product := b.products[x]
		if product == 0 {
			log.Fatalf("put comment ID 0? %v %v", x, b.products[x])
		}
		//		bidder := b.users[int(ddtxn.RandN(local_seed, b.sp))+w*int(b.sp)]
		bidder := b.users[int(ddtxn.RandN(local_seed, uint32(b.nbidders)))]
		txn.U1 = uint64(bidder)
		txn.U2 = uint64(product)
	} else if x < b.rates[7] {
		txn.TXN = ddtxn.RUBIS_REGISTER
		txn.U1 = uint64(ddtxn.RandN(local_seed, uint32(ddtxn.NUM_REGIONS)))
		txn.U2 = uint64(ddtxn.RandN(local_seed, 1000000000))
	} else if x < b.rates[8] {
		txn.TXN = ddtxn.RUBIS_SEARCHCAT
		txn.U1 = uint64(ddtxn.RandN(local_seed, uint32(ddtxn.NUM_CATEGORIES)))
		txn.U2 = 5
	} else if x < b.rates[9] {
		txn.TXN = ddtxn.RUBIS_SEARCHREG
		txn.U1 = uint64(ddtxn.RandN(local_seed, uint32(ddtxn.NUM_REGIONS)))
		txn.U2 = uint64(ddtxn.RandN(local_seed, uint32(ddtxn.NUM_CATEGORIES)))
		txn.U3 = 5
	} else if x < b.rates[10] {
		txn.TXN = ddtxn.RUBIS_VIEW
		x := ddtxn.RandN(local_seed, uint32(b.nproducts))
		product := b.products[x]
		if product == 0 {
			log.Fatalf("view ID 0? %v %v", x, b.products[x])
		}
		txn.U1 = uint64(product)
	} else if x < b.rates[11] {
		txn.TXN = ddtxn.RUBIS_VIEWUSER
		//		bidder := b.users[int(ddtxn.RandN(local_seed, b.sp))+w*int(b.sp)]
		bidder := b.users[int(ddtxn.RandN(local_seed, uint32(b.nbidders)))]
		txn.U1 = uint64(bidder)
	} else {
		log.Fatalf("No such transaction\n")
	}
}