Exemplo n.º 1
0
Arquivo: main.go Projeto: taysom/tau
func newtree(args []string) {
	name := ".btree"
	if len(args) > 0 {
		name = args[0]
	}
	Btree.Cache = buf.NewCache(name, 10, 1<<8)
	if Btree.Cache == nil {
		fmt.Fprintln(os.Stderr, "new cache failed", name)
		return
	}
}
Exemplo n.º 2
0
Arquivo: main.go Projeto: taysom/tau
func btreetest() {
	var mytree btree.Btree
	name := ".btree"
	mytree.Cache = buf.NewCache(name, 10, 1<<8)
	if mytree.Cache == nil {
		fmt.Fprintln(os.Stderr, "new cache failed", name)
		return
	}
	mytree.Insert([]byte("abc"), []byte("efghij"))
	mytree.Insert([]byte("bcde"), []byte("fghijklmnop"))
	for i := 0; i < 9; i++ {
		mytree.Insert(rndSlice(), rndSlice())
	}
	mytree.Print()
}
Exemplo n.º 3
0
Arquivo: main.go Projeto: taysom/tau
func cachetest(args []string) {
	cachefile := "/tmp/cache"
	if len(args) > 0 {
		cachefile = args[0]
	}
	fmt.Printf("cache file = %s\n", cachefile)
	cache := buf.NewCache(cachefile, 10, 1<<8)
	if cache == nil {
		return
	}

	// Test 1. Get a buffer, set a value, and Put it back
	b := cache.NewBuf()
	test(b != nil)
	test(b.Blkno == 1)
	b.Data[0] = 'A'
	fmt.Printf("b=%p\n", b)
	b.Put()

	cache.Clear()

	// Test 2. Get the buffer from test 1 and check it has what we set
	// This is not a good test, because it depends on test 1.
	// This test did fail to detect that we read the block into a
	// separate buffer. Now we have to copies of the buffer in memory.
	b = cache.GetBuf(1)
	fmt.Printf("b=%p\n", b)
	fmt.Println("b=", b)
	test(b != nil)
	test(b.Blkno == 1)
	test(b.Data[0] == 'A')
	b.Put()
	test(cache.Audit())

	// Test 3. Use up all the buffers without releasing any of them
	// Can't really test for running off of end nor can we test for
	// infinite loops.
	for i := 0; i < len(cache.Buf); i++ {
		b = cache.GetBuf(int64(i))
		b.Put()
	}
	b = cache.GetBuf(int64(len(cache.Buf)))
	test(b != nil)

	test(cache.Audit())
}
Exemplo n.º 4
0
Arquivo: bt.go Projeto: taysom/tau
func NewBtree(devname string) *Btree {
	btree := new(Btree)
	btree.cache = buf.NewCache(devname, NumBufs, LenBuf)
	return btree
}