Example #1
0
//Called at startup of a normal run
func (sp *CephStorageProvider) Initialize(opts map[string]string) {
	//Allocate caches
	sp.rcache = &CephCache{}
	cachesz, _ := strconv.Atoi(opts["cephrcache"])
	if cachesz < 40 {
		cachesz = 40 //one per read handle: 40MB
	}
	sp.rcache.initCache(uint64(cachesz))

	cephconf := C.CString(opts["cephconf"])
	cephpool := C.CString(opts["cephpool"])
	_, err := C.initialize_provider(cephconf, cephpool)
	if err != nil {
		log.Panic("CGO ERROR: %v", err)
	}
	C.free(unsafe.Pointer(cephconf))
	C.free(unsafe.Pointer(cephpool))

	sp.rh = make([]C.phandle_t, NUM_RHANDLES)
	sp.rh_avail = make([]bool, NUM_RHANDLES)
	sp.rhidx = make(chan int, NUM_RHANDLES+1)
	sp.rhidx_ret = make(chan int, NUM_RHANDLES+1)
	sp.alloc = make(chan uint64, 128)
	sp.segaddrcache = make(map[[16]byte]uint64, SEGCACHE_SIZE)
	sp.chunkgate = make(map[chunkreqindex][]chan []byte)

	for i := 0; i < NUM_RHANDLES; i++ {
		sp.rh_avail[i] = true
		h, err := C.handle_create()
		if err != nil {
			log.Panic("CGO ERROR: %v", err)
		}
		sp.rh[i] = h
	}

	//Obtain base address
	sp.ptr = sp.obtainBaseAddress()
	if sp.ptr == 0 {
		log.Panic("Could not read allocator! DB not created properly?")
	}
	log.Info("Base address obtained as 0x%016x", sp.ptr)

	//Start serving read handles
	go sp.provideReadHandles()

	//Start providing address allocations
	go sp.provideAllocs()

}
Example #2
0
//Called to create the database for the first time
func (sp *CephStorageProvider) CreateDatabase(opts map[string]string) error {
	cephconf := C.CString(opts["cephconf"])
	cephpool := C.CString(opts["cephpool"])
	_, err := C.initialize_provider(cephconf, cephpool)
	if err != nil {
		log.Panic("CGO ERROR: %v", err)
	}
	C.free(unsafe.Pointer(cephconf))
	C.free(unsafe.Pointer(cephpool))
	h, err := C.handle_create()
	if err != nil {
		log.Panic("CGO ERROR: %v", err)
	}
	C.handle_init_allocator(h)
	_, err = C.handle_close(h)
	if err != nil {
		log.Panic("CGO ERROR: %v", err)
	}
	return nil
}