libkv icon indicating copy to clipboard operation
libkv copied to clipboard

can not get zookeeper path data, node cannot be discovery.

Open rl5c opened this issue 7 years ago • 0 comments

zookeeper version: 3.4.6 this problem description: If you use the zk store lib, you will find that when the same node repeatedly goes online and offline, the node can no longer be discovery. After the investigation, it is found that the node path exists in zk, but the data cannot be obtained and the data is empty.

Previous code:store/zookeeper/zookeeper.go line 68.

func (s *Zookeeper) Get(key string) (pair *store.KVPair, err error) {
	resp, meta, err := s.client.Get(s.normalize(key))

	if err != nil {
		if err == zk.ErrNoNode {
			return nil, store.ErrKeyNotFound
		}
		return nil, err
	}

	// FIXME handle very rare cases where Get returns the
	// SOH control character instead of the actual value
	if string(resp) == SOH {
		return s.Get(store.Normalize(key))
	}

	pair = &store.KVPair{
		Key:       key,
		Value:     resp,
		LastIndex: uint64(meta.Version),
	}

	return pair, nil
}

Modified code, the problem disappears, hope to adopt.

func (s *Zookeeper) Get(key string) (pair *store.KVPair, err error) {
	resp, meta, err := s.client.Get(s.normalize(key))

	if err != nil {
		if err == zk.ErrNoNode {
			return nil, store.ErrKeyNotFound
		}
		return nil, err
	}
	
	// FIXME handle very rare cases where Get returns the
	// SOH control character instead of the actual value
	if string(resp) == SOH || string(resp) == "" {  //If the data is empty, you can get it again.
		return s.Get(key)  //get by original key
	}

	pair = &store.KVPair{
		Key:       key,
		Value:     resp,
		LastIndex: uint64(meta.Version),
	}

	return pair, nil
}

rl5c avatar Mar 31 '18 08:03 rl5c