Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I wonder if there was a design intention about returning KeyValue. #40

Closed
yunkon-kim opened this issue Jul 22, 2024 · 2 comments
Closed
Assignees
Labels
question Further information is requested

Comments

@yunkon-kim
Copy link
Member

@powerkimhub (cc. @seokho-son)

CB-Tumblebug에서는 cb-store와 sqlite를 활용해 메타데이터/데이터를 운영 및 관리하고 있는데요.

이후 CB-Tumblebug에서 메타데이터/데이터 저장소의 개선을 계획하고 있습니다. 관련하여 cb-store에 한 가지 궁금한 사항이 있어 문의드립니다(유용한 디자인 패턴을 살리고자 문의드리는 사항입니다).

아래 Get(), GetList()의 리턴 타입이 String 형태의 Value 대신, KeyValue 객체를 리턴하도록 되어 있던데요. 디자인 상에서 어떤 의도가 있으셨는지 궁금합니다.

// Get - 지정한 키의 값을 ETCD의 데이터에서 추출
func (etcdDriver *ETCDDriver) Get(key string) (*icbs.KeyValue, error) {
// ETCD 환경 확인
if nil == cli {
return nil, errNoETCD
}
config.Cblogger.Info("Key:" + key)
resp, err := cli.Get(ctx, key)
if err != nil {
config.Cblogger.Error(err)
return nil, err
}
for _, ev := range resp.Kvs {
keyValue := icbs.KeyValue{Key: string(ev.Key), Value: string(ev.Value)}
return &keyValue, nil
}
//return nil, fmt.Errorf("No Results with %s Key!!", key)
return nil, nil
}
// GetList - 지정한 키와 정렬 조건을 기준으로 ETCD의 데이터에서 추출
func (etcdDriver *ETCDDriver) GetList(key string, sortAscend bool) ([]*icbs.KeyValue, error) {
// ETCD 환경 확인
if nil == cli {
return nil, errNoETCD
}
config.Cblogger.Info("Key:" + key + ", sortAscend:" + strconv.FormatBool(sortAscend))
order := clientv3.SortAscend
if !sortAscend {
order = clientv3.SortDescend
}
resp, err := cli.Get(ctx, key, clientv3.WithPrefix(), clientv3.WithSort(clientv3.SortByKey, order))
if err != nil {
config.Cblogger.Error(err)
return nil, err
}
keyValueList := make([]*icbs.KeyValue, len(resp.Kvs))
for k, ev := range resp.Kvs {
tmpOne := icbs.KeyValue{Key: string(ev.Key), Value: string(ev.Value)}
keyValueList[k] = &tmpOne
}
return keyValueList, nil
}

@yunkon-kim yunkon-kim added the question Further information is requested label Jul 22, 2024
@powerkimhub powerkimhub self-assigned this Jul 22, 2024
@powerkimhub
Copy link
Member

@yunkon-kim (@seokho-son


[GetList]

[Get]

  • Get은 exact match이어서 사용자가 반환 받은 Value에 대한 Key를 이미 정확하게 알고 있지만,
  • Get으로 얻은 값이 상위 호출한 함수에서 사용되거나 또는 다른 곳으로 전달과 전달이 되었을 때
    • 결과가 String 타입이면: cb-store 사용자가 Key를 계속 전달하고, 유지해야함
    • 결과가 KeyValue 타입이면: Key 전달이 불필요하고, Key든 Value든 값이 사용자가 필요한 경우 활용 가능

@yunkon-kim
Copy link
Member Author

@powerkimhub

(KV store에서 값을 얻은 이후) KeyValue가 여러 부분에서 활용되는 측면까지 고려하신 설계로 이해하였습니다. 설명해주셔서 감사합니다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants