当前位置: 首页>>代码示例>>Golang>>正文


Golang lsplog.Vlogf函数代码示例

本文整理汇总了Golang中P2-f12/official/lsplog.Vlogf函数的典型用法代码示例。如果您正苦于以下问题:Golang Vlogf函数的具体用法?Golang Vlogf怎么用?Golang Vlogf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Vlogf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: iNewLibstore

func iNewLibstore(server, myhostport string, flags int) (*Libstore, error) {
	ls := new(Libstore)
	lsplog.Vlogf(3, "[iNewLibstore] Libstore flag %d", flags)
	ls.cache = make(map[string]*Leased)
	ls.cacheLocker = new(sync.Mutex)
	ls.cacheCallbackHostPort = myhostport
	if flags == NONE {
		ls.requests = make(map[string]*Request)
		ls.requestsLocker = new(sync.Mutex)
	}
	if myhostport != "" {
		go ls.revokeLeasesListenerInit(myhostport)
		go ls.cleanCache()
	}
	ls.flags = flags
	masterConnection, e := rpc.DialHTTP("tcp", server)
	if e != nil {
		lsplog.Vlogf(3, "[iNewLibstore] Error while connecting master node")
		return nil, e
	}

	ls.connections = make(map[string]*rpc.Client)
	ls.connections[server] = masterConnection

	e = ls.getServers(masterConnection)
	if e != nil {
		return nil, e
	}
	return ls, nil
}
开发者ID:ammarar,项目名称:DS-P2,代码行数:30,代码来源:libstore-impl.go

示例2: checkWhetherLeaseNeeded

func (ls *Libstore) checkWhetherLeaseNeeded(args *storageproto.GetArgs, key string) {
	if ls.flags == ALWAYS_LEASE {
		args.WantLease = true
		args.LeaseClient = ls.cacheCallbackHostPort
	} else if ls.cacheCallbackHostPort == "" {
		args.WantLease = false
	} else {
		ls.requestsLocker.Lock()
		if ls.requests[key] == nil {
			lsplog.Vlogf(3, "[checkWhetherLeaseNeeded] First requested")
			req := &Request{1, time.Now().Add(time.Duration(storageproto.QUERY_CACHE_SECONDS) * time.Second)}
			ls.requests[key] = req
		} else {
			req := ls.requests[key]
			if time.Now().Before(req.ts) {
				req.frequency = req.frequency + 1
				if req.frequency >= storageproto.QUERY_CACHE_THRESH {
					lsplog.Vlogf(3, "[checkWhetherLeaseNeeded] Going to ask for a lease")
					args.LeaseClient = ls.cacheCallbackHostPort
					args.WantLease = true
				} else {
					args.WantLease = false
				}
			} else {
				delete(ls.requests, key)
				args.WantLease = false
			}
		}
		ls.requestsLocker.Unlock()
	}
}
开发者ID:ammarar,项目名称:DS-P2,代码行数:31,代码来源:libstore-impl.go

示例3: GetList

func (ss *Storageserver) GetList(args *storageproto.GetArgs,
	reply *storageproto.GetListReply) error {

	lsplog.Vlogf(3, "storage try to getlist with key %s", args.Key)

	//ss.rwlock.RLock()

	val, present := ss.hash[args.Key]
	if !present {
		if ss.numnodes == 1 {
			reply.Status = storageproto.EKEYNOTFOUND
		} else {
			reply.Status = storageproto.EWRONGSERVER
		}
		reply.Value = nil
		//ss.rwlock.RUnlock()
		return nil
	}

	lsplog.Vlogf(3, "storage getlist key %s, val %s", args.Key, val)

	err := json.Unmarshal([]byte(val), &(reply.Value))
	if err != nil {
		lsplog.Vlogf(0, "WARNING: unmarshal data generate an error")
	}

	reply.Status = storageproto.OK

	if args.WantLease {
		ss.addLeasePool(args, &(reply.Lease))
	}

	//ss.rwlock.RUnlock()
	return nil
}
开发者ID:yuguess,项目名称:440_P2,代码行数:35,代码来源:storageimpl.go

示例4: getServers

func (ls *Libstore) getServers(masterConnection *rpc.Client) error {
	lsplog.Vlogf(1, "Getting nodes from masters")
	args := new(storageproto.GetServersArgs)
	var reply storageproto.RegisterReply
	e := masterConnection.Call("StorageRPC.GetServers", &args, &reply)
	if e != nil {
		return e
	}
	numberOfTries := 0
	for !reply.Ready {
		time.Sleep(WAIT_FOR_STORAGE_SLEEP * time.Second)
		if numberOfTries < RETRY_THRESH {
			e := masterConnection.Call("StorageRPC.GetServers", &args, &reply)
			if e != nil {
				lsplog.Vlogf(3, "Connection to master failed")
				return e
			}
			numberOfTries++
		} else {
			return lsplog.MakeErr("Waited too long for storage server to be ready")
		}
	}
	lsplog.Vlogf(1, "servers %+v", reply.Servers)
	ls.servers = reply.Servers
	return nil
}
开发者ID:ammarar,项目名称:DS-P2,代码行数:26,代码来源:libstore-impl.go

示例5: CreateUser

/**@brief create a new user
 * @param CreateUserArgs
 * @param CreateUserReply
 * @return error
 */
func (ts *Tribserver) CreateUser(
	args *tribproto.CreateUserArgs, reply *tribproto.CreateUserReply) error {

	var trib_key, fllw_key string
	var err error

	trib_key = fmt.Sprintf("%s:T", args.Userid)
	fllw_key = fmt.Sprintf("%s:F", args.Userid)

	_, err = ts.Store.GetList(trib_key)
	if err == nil {
		lsplog.Vlogf(0, "try create user %s , but exist !", args.Userid)
		reply.Status = tribproto.EEXISTS
		return nil
	}

	err = ts.Store.Put(trib_key, "")
	if lsplog.CheckReport(2, err) {
		lsplog.Vlogf(0, "user %s , trib_key exist !", args.Userid)
		reply.Status = tribproto.EEXISTS
		return nil
	}

	err = ts.Store.Put(fllw_key, "")
	if lsplog.CheckReport(2, err) {
		reply.Status = tribproto.EEXISTS
		return nil
	}

	reply.Status = tribproto.OK

	lsplog.Vlogf(0, "create user status %d", tribproto.OK)

	return nil
}
开发者ID:yuguess,项目名称:440_P2,代码行数:40,代码来源:trib-impl.go

示例6: iNewLibstore

/**@brief helper function for sorting
 * @param server master storage server addr
 * @param myhostport trib server's port
 * @param flags
 * @return *Libstore
 * @return error
 */
func iNewLibstore(server, myhostport string, flags int) (*Libstore, error) {
	var store Libstore
	var master *rpc.Client
	var args storageproto.GetServersArgs
	var reply storageproto.RegisterReply
	var err error

	store.Addr = myhostport
	store.Flags = flags

	if store.Addr != "" {
		rpc.Register(cacherpc.NewCacheRPC(&store))
	}

	lsplog.Vlogf(3, "libstore try to connect to master storage %s", server)

	master, err = rpc.DialHTTP("tcp", server)
	if lsplog.CheckReport(1, err) {
		return nil, err
	}

	lsplog.Vlogf(3, "try to call GetServers")

	master.Call("StorageRPC.GetServers", &args, &reply)

	if !reply.Ready {
		for i := 0; i < 5; i++ {
			time.Sleep(1000 * time.Millisecond)
			master.Call("StorageRPC.GetServers", &args, &reply)
		}
	}

	err = master.Close()
	if lsplog.CheckReport(1, err) {
		lsplog.Vlogf(3, "WARNING close master failed")
	}

	// couldn't get list of servers from master
	if (reply.Ready == false) || (reply.Servers == nil) {
		return nil, lsplog.MakeErr("Storage system not ready.")
	}

	store.Nodes = reply.Servers
	store.RPCConn = make([]*rpc.Client, len(store.Nodes))

	sort.Sort(store.Nodes)
	/*
	  for i := 0; i < len(store.Nodes); i++ {
	    fmt.Printf("%v\n", store.Nodes[i])
	  }*/

	store.Leases = cache.NewCache()
	if lsplog.CheckReport(1, err) {
		return nil, err
	}

	lsplog.Vlogf(3, "libstore create complete")

	return &store, nil
}
开发者ID:yuguess,项目名称:440_P2,代码行数:67,代码来源:libstore-impl.go

示例7: CheckWithinRange

func (ss *Storageserver) CheckWithinRange(key string) bool {
	if !ss.multiNodes {
		lsplog.Vlogf(1, "[CheckWithinRange] Within range [Single node]")
		return true
	}
	hash := getServerIndicator(key)
	result := ss.getSuccessor(hash) == ss.nodeid
	lsplog.Vlogf(1, "[CheckWithinRange] Key within range %v", result)
	return result
}
开发者ID:ammarar,项目名称:DS-P2,代码行数:10,代码来源:storageimpl.go

示例8: RemoveFromList

func (ss *Storageserver) RemoveFromList(args *storageproto.PutArgs,
	reply *storageproto.PutReply) error {
	lsplog.Vlogf(0, "removeFromList key %s", args.Key)

	//ss.rwlock.Lock()

	val, present := ss.hash[args.Key]
	if !present {
		lsplog.Vlogf(3, "try to remove, key %s does not exist", args.Key)
		reply.Status = storageproto.EKEYNOTFOUND
		//ss.rwlock.Unlock()
		return nil
	}

	entry, present := ss.leasePool[args.Key]

	if present {
		entry.mtx.Lock()
		ss.revokeLeaseHolders(args.Key)

	}

	var list []string
	err := json.Unmarshal([]byte(val), &list)
	if err != nil {
		lsplog.Vlogf(0, "WARNING: unmarshal data generate an error")
	}

	for i, v := range list {
		if v == args.Value {
			list = append(list[:i], list[i+1:]...)

			ss.hash[args.Key], err = json.Marshal(list)
			if err != nil {
				lsplog.Vlogf(0, "WARNING: Marshal data generate an error")
			}

			reply.Status = storageproto.OK
			//ss.rwlock.Unlock()
			return nil
		}
	}

	reply.Status = storageproto.EITEMNOTFOUND
	if present {
		entry.mtx.Unlock()
	}
	//ss.rwlock.Unlock()
	return nil
}
开发者ID:yuguess,项目名称:440_P2,代码行数:50,代码来源:storageimpl.go

示例9: Get

func (ss *Storageserver) Get(args *storageproto.GetArgs, reply *storageproto.GetReply) error {
	if !ss.CheckWithinRange(args.Key) {
		reply.Status = storageproto.EWRONGSERVER
		lsplog.Vlogf(1, "[Get] The key is given to the wrong server")
		return nil
	}
	if args.WantLease {
		ss.modifyingLock.Lock()
		if ss.modifying[args.Key] != nil {
			reply.Lease.Granted = false
		} else {
			reply.Lease.Granted = true
			ss.leasesLock.Lock()
			currentLeaseList := ss.leases[args.Key]
			if currentLeaseList == nil {
				currentLeaseList = list.New()
			}
			currentLeaseList.PushBack(&ClientLease{args.LeaseClient, time.Now().Add((storageproto.LEASE_SECONDS + storageproto.LEASE_GUARD_SECONDS) * time.Second)})
			ss.leasesLock.Unlock()
		}
		ss.modifyingLock.Unlock()
	}
	ss.storageLock.Lock()
	if ss.storage[args.Key] == nil {
		reply.Status = storageproto.EKEYNOTFOUND
	} else {
		reply.Value = *ss.storage[args.Key]
		reply.Status = storageproto.OK
	}
	ss.storageLock.Unlock()
	return nil
}
开发者ID:ammarar,项目名称:DS-P2,代码行数:32,代码来源:storageimpl.go

示例10: Get

// RPC-able interfaces, bridged via StorageRPC.
// These should do something! :-)
func (ss *Storageserver) Get(args *storageproto.GetArgs,
	reply *storageproto.GetReply) error {
	//ss.rwlock.RLock()
	fmt.Printf("try to GET key %s\n", args.Key)

	val, present := ss.hash[args.Key]
	if !present {
		//if the whole system only have one storage node
		if ss.numnodes == 1 {
			reply.Status = storageproto.EKEYNOTFOUND
		} else {
			//reply.Status = storageproto.EKEYNOTFOUND
			reply.Status = storageproto.EWRONGSERVER
		}

		fmt.Printf("storage GET key %s failed, nonexist\n", args.Key)
		//ss.rwlock.RUnlock()
		return nil
	}

	err := json.Unmarshal([]byte(val), &(reply.Value))
	if err != nil {
		lsplog.Vlogf(0, "WARNING: unmarshal data generate an error")
	}

	if args.WantLease {
		ss.addLeasePool(args, &(reply.Lease))
	}

	fmt.Printf("Storage Get key %s, val %s, lease %t\n",
		args.Key, reply.Value, reply.Lease.Granted)
	reply.Status = storageproto.OK
	//ss.rwlock.RUnlock()
	return nil
}
开发者ID:yuguess,项目名称:440_P2,代码行数:37,代码来源:storageimpl.go

示例11: GetServer

/**@brief Hashes a key and returns an RPC connection to the server
         responsible for storing it. If an RPC connection is not
         established, create one and store it for future accesses.
* @param server master server addr
* @param myhostport trib server's port
* @param flags
* @return *Libstore
* @return error
*/
func (ls *Libstore) GetServer(key string) (*rpc.Client, error) {
	var id uint32
	var svr int
	var err error

	//lsplog.Vlogf(3, "libstore GetServer Invoked")

	id = Storehash(strings.Split(key, ":")[0])

	// returns the index of the first server after the key's hash
	svr = sort.Search(
		len(ls.Nodes), func(i int) bool { return ls.Nodes[i].NodeID >= id })
	svr = (svr) % len(ls.Nodes)

	//lsplog.Vlogf(0, "%s -> %d (%d)\n", key, id, svr)

	if ls.RPCConn[svr] == nil {
		lsplog.Vlogf(0, "Caching RPC connection to %s.\n", ls.Nodes[svr].HostPort)
		ls.RPCConn[svr], err = rpc.DialHTTP("tcp", ls.Nodes[svr].HostPort)
		if lsplog.CheckReport(1, err) {
			return nil, err
		}
	}

	return ls.RPCConn[svr], nil
}
开发者ID:yuguess,项目名称:440_P2,代码行数:35,代码来源:libstore-impl.go

示例12: main

func main() {
	lsplog.SetVerbose(10)
	ls, e := libstore.NewLibstore("localhost:9009", "localhost:9999", 0)
	e = ls.AppendToList("ammar:hey", "Helly")
	e = ls.AppendToList("ammar:hey", "Helly")
	e = ls.AppendToList("ammar:hey", "Kelly")
	lsplog.Vlogf(1, "%v", e)
	var k []string
	k, e = ls.GetList("ammar:hey")
	lsplog.Vlogf(1, "%v %v", k, e)
	e = ls.RemoveFromList("ammar:hey", "Helly")
	lsplog.Vlogf(1, "%v ", e)
	e = ls.RemoveFromList("ammar:hey", "Helly")
	lsplog.Vlogf(1, "%v ", e)
	k, e = ls.GetList("ammar:hey")
	lsplog.Vlogf(1, "%v %v", k, e)
}
开发者ID:ammarar,项目名称:DS-P2,代码行数:17,代码来源:storagetest.go

示例13: getServerConnection

func (ls *Libstore) getServerConnection(indicator uint32) (*rpc.Client, error) {
	if len(ls.servers) == 1 {
		return ls.connections[ls.servers[0].HostPort], nil
	}
	var smallest uint32
	smallest = math.MaxUint32
	smallNodeIndex := 0
	nodeIndex := 0
	for i := range ls.servers {
		if smallest > ls.servers[i].NodeID {
			smallest = ls.servers[i].NodeID
			smallNodeIndex = i
		}
	}

	var successor *uint32
	for i := range ls.servers {
		if indicator <= ls.servers[i].NodeID {
			if successor == nil || ls.servers[i].NodeID < *successor {
				successor = &ls.servers[i].NodeID
				nodeIndex = i
				lsplog.Vlogf(1, "[libstore] Updated to successor %v and index %v", ls.servers[i].NodeID, i)
			}
		}
	}

	if successor == nil {
		nodeIndex = smallNodeIndex
		successor = &smallest
	}

	hostport := ls.servers[nodeIndex].HostPort
	lsplog.Vlogf(3, "[getServerConnection] Successfor NodeID is %v and its host:port is %s and index %v", *successor, hostport, nodeIndex)
	if ls.connections[hostport] == nil {
		lsplog.Vlogf(3, "[getServerConnection] Connection for %s is not created. Creating connection...", hostport)
		con, e := rpc.DialHTTP("tcp", hostport)
		if e != nil {
			lsplog.Vlogf(3, "[getServerConnection] Connection for %s failed", hostport)
			return nil, e
		}
		lsplog.Vlogf(3, "[getServerConnection] Connection created successfully")
		ls.connections[hostport] = con
	}
	return ls.connections[hostport], nil
}
开发者ID:ammarar,项目名称:DS-P2,代码行数:45,代码来源:libstore-impl.go

示例14: Put

func (ss *Storageserver) Put(args *storageproto.PutArgs,
	reply *storageproto.PutReply) error {
	var err error

	fmt.Printf("st svr put invoked key %s, val %s !!!\n", args.Key, args.Value)

	//ss.rwlock.Lock()
	if entry, present := ss.leasePool[args.Key]; present {
		fmt.Printf("try to put to %s still lease pool, call revoke!!!\n", args.Key)
		entry.mtx.Lock()
		ss.revokeLeaseHolders(args.Key)
		entry.mtx.Unlock()
	}

	_, present := ss.hash[args.Key]
	if present {
		ss.hash[args.Key], _ = json.Marshal(args.Value)
		reply.Status = storageproto.OK
		//ss.rwlock.Unlock()
		return nil
	}

	if args.Value == "" {
		lsplog.Vlogf(3, "storage first put %s", args.Key)
		ss.hash[args.Key], err = json.Marshal([]string{})
	} else {
		//fmt.Printf("storage put %s, val %s", args.Key, args.Value)
		ss.hash[args.Key], err = json.Marshal(args.Value)
	}

	if err != nil {
		lsplog.Vlogf(0, "WARNING: Marshal data generate an error")
	}

	reply.Status = storageproto.OK

	//ss.rwlock.Unlock()
	//fmt.Println("storage put complete!")
	return nil
}
开发者ID:yuguess,项目名称:440_P2,代码行数:40,代码来源:storageimpl.go

示例15: iAppendToList

func (ls *Libstore) iAppendToList(key, newitem string) error {
	indicator := ls.getServerIndicator(key)
	con, e := ls.getServerConnection(indicator)
	if e != nil {
		return e
	}
	args := &storageproto.PutArgs{key, newitem}
	var reply storageproto.PutReply
	lsplog.Vlogf(1, "Calling RPC StorageRPC.AppendToList with key %s and value %s", key, newitem)
	e = con.Call("StorageRPC.AppendToList", args, &reply)
	if e != nil {
		return e
	}
	lsplog.Vlogf(1, "Called RPC StorageRPC.AppendToList successfully")
	lsplog.Vlogf(1, "Status recieved %v", reply.Status)

	if reply.Status == storageproto.EWRONGSERVER {
		lsplog.Vlogf(1, "Key %s should not be called from server", key)
		return lsplog.MakeErr("Wrong server is called")
	} else if reply.Status == storageproto.EITEMNOTFOUND {
		lsplog.Vlogf(1, "Item to add not found in server")
		return lsplog.MakeErr("Error: item to add not found")
	} else if reply.Status == storageproto.EITEMEXISTS {
		lsplog.Vlogf(1, "Item to add alrady exists")
		return lsplog.MakeErr("Error: item to add exists")
	}
	return nil
}
开发者ID:ammarar,项目名称:DS-P2,代码行数:28,代码来源:libstore-impl.go


注:本文中的P2-f12/official/lsplog.Vlogf函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。