Code Monkey home page Code Monkey logo

cb-store's Introduction

cb-store

GitHub go.mod Go version GoDoc    Release Version License

cb-store is a common repository for managing Meta Info of Cloud-Barista. You can choose NUTSDB or ETCD for repository of cb-store.

[NOTE]
cb-store is currently under development.
So, we do not recommend using the current release in production.
Please note that the functionalities of cb-store are not stable and secure yet.
If you have any difficulties in using cb-store, please let us know.
(Open an issue or Join the cloud-barista Slack)

1. install cb-store library pkg

2. example & test

  • example: https://github.com/cloud-barista/cb-store/blob/master/test/test.go

  • install ETCD (Client V3.0): When using ETCD

  • $ cd test

  • $ go run test.go

    =========================== Put(...)
    </> root
    </key1> value
    </key1> value1
    </key1/> value2
    </key1/%> value3%
    </key1/key2/key3> value4
    </space key> space value5
    </newline
     key> newline
     value6
    </a/b/c/123/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u> value/value/value
    ===========================
    =========================== Get("/")
    </> root
    ===========================
    =========================== Get("space key")
    </space key> space value5
    ===========================
    =========================== GetList("/", Ascending)
    </> root
    </a/b/c/123/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u> value/value/value
    </key1> value1
    </key1/> value2
    </key1/%> value3%
    </key1/key2/key3> value4
    </newline
     key> newline
     value6
    </space key> space value5
    ===========================
    =========================== GetList("/", Descending)
    </space key> space value5
    </newline
     key> newline
     value6
    </key1/key2/key3> value4
    </key1/%> value3%
    </key1/> value2
    </key1> value1
    </a/b/c/123/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u> value/value/value
    </> root
    
    

cb-store's People

Contributors

ccambo avatar dependabot[bot] avatar jihoon-seo avatar jin-whee-park avatar powerkimhub avatar seokho-son avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

cb-store's Issues

[ETCD Driver] go module build error

Go module(export GO111MODULE=on) build 시 오류.

go: finding github.com/coreos/go-systemd/journal latest
go: finding github.com/coreos/go-systemd latest
go: downloading github.com/coreos/go-systemd v0.0.0-20200109085637-d657f9650837
/root/go/pkg/mod/github.com/coreos/[email protected]+incompatible/pkg/logutil/zap_journal.go:29:2: unknown import path "github.com/coreos/go-systemd/journal": cannot find module providing package github.com/coreos/go-systemd/journal

[설정 파일 내부 환경변수 미처리 문제]

  • CB-Store 설정은 $CBSTORE_ROOT/conf/store_conf.yaml 파일을 사용함.
  • 현재 설정 파일 내부에서 환경변수 사용이 불가능함.
  • 아래와 같이 설정하면, 실행 위치에 '$CBSTORE_ROOT/meta_db/dat' 경로가 생성됨.
$vi $CBSTORE_ROOT/conf/store_conf.yaml
    ...
    dbpath: "$CBSTORE_ROOT/meta_db/dat"
    ...

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

@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
}

[etcd driver] upgrade used etcd & go pkg

  • cb-store는 key/value store 추상화하여 여러 store를 동일하게 사용할 수 있습니다.
  • key/value store 중 etcd를 사용할 수 있습니다.
  • etcd driver는 개발한지 오래 되서 old한 etcd client 및 grpc pkg를 import합니다.
  • 이는 사용되는 다른 pkg들이 etcd client나 grpc pkg를 사용할 때 제약 사항이 됩니다.
  • 관련하여, etcd driver 업그레이드가 필요합니다.

[portability-bug] error of meta info location on MacOS

Mac에서 실행시 동작에는 문제 없지만,
환경변수가 풀리지 않고, 실행위치 아래 path로 생성됨. (잠재적인 문제 존재)

  • [want] /root/go/src/github.com/cloud-barista/cb-spider/meta_db/dat
  • [now] $CBSTORE_ROOT/meta_db/dat ($PWD 아래 생성)

Config: YAML vs. env var

현재:

[CB-Spider]

[setup.env]

export CBSPIDER_ROOT=$GOPATH/src/github.com/cloud-barista/cb-spider
export CBSTORE_ROOT=$GOPATH/src/github.com/cloud-barista/cb-spider
export CBLOG_ROOT=$GOPATH/src/github.com/cloud-barista/cb-spider

[store_conf.yaml]

storetype: NUTSDB
#storetype: ETCD

nutsdb:
  dbpath: "$CBSTORE_ROOT/meta_db/dat"
  segmentsize: 1048576  # 1048576 1024*1024 (1MB)

etcd:
  etcdserverport: "129.254.175.43:2379"

[log_conf.yaml]

cblog:
  ## true | false
  loopcheck: false # This temp method for development is busy wait. cf) cblogger.go:levelSetupLoop().

  ## debug | info | warn | error
  loglevel: info # If loopcheck is true, You can set this online.

  ## true | false
  logfile: true

## Config for File Output ##
logfileinfo:
  filename: ./log/cblogs.log
  maxsize: 10 # megabytes
  maxbackups: 50
  maxage: 31 # days

[CB-Tumblebug]

[setup.env]

export CBSTORE_ROOT=$GOPATH/src/github.com/cloud-barista/cb-tumblebug
export CBLOG_ROOT=$GOPATH/src/github.com/cloud-barista/cb-tumblebug
export SPIDER_URL=http://localhost:1024

[store_conf.yaml]

상동

[log_conf.yaml]

상동

env var 로 되어 있는 것은
docker run 이나 docker-compose up 으로 Spider, TB 실행할 때
손쉽게 변경할 수 있는데,

yaml 안에 있는 것은

  1. yaml 파일을 수정하고 컨테이너 이미지를 다시 만들어서 실행 (매우 안 좋은 방법)
  2. Dockerfilesed 명령을 넣어서 변경 (사실 1번과 동일함)
  3. 호스트 머신에 있는 yaml 파일을 수정하고, Docker 의 volume mount 기능을 이용하여, 컨테이너 실행

등의 방법으로 수정하여 실행할 수 있겠습니다.


그런데 장기적으로 생각해 보면
CB 시스템을 Helm chart 로 작성하여 K8s 클러스터에 배포할 것이기 때문에
이를 고려해야 합니다.

Helm 에는 values.yaml 파일이 있고,
https://helm.sh/docs/chart_template_guide/values_files/
여기를 보면

values.yaml

favoriteDrink: coffee

이렇게 적고

K8s ConfigMap template 에

apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ .Release.Name }}-configmap
data:
  myvalue: "Hello World"
  drink: {{ .Values.favoriteDrink }}

이렇게 적으면

apiVersion: v1
kind: ConfigMap
metadata:
  name: good-puppy-configmap
data:
  myvalue: "Hello World"
  drink: coffee

이렇게 K8s ConfigMap yaml 로 render 된다고 합니다.


[K8s ConfigMap]
https://arisu1000.tistory.com/27843

ConfigMap 에 써 있는 값들은
K8s 컨테이너에

  1. 환경 변수로 적용되거나 (예: DEBUG_LEVEL=debug)
  2. 컨테이너 안의 임의의 경로(예: /etc/config)에 파일 형태로 (예: DB_URL 이라는 파일, 내용은 http://...

둘 중 하나의 형태로 적용됩니다.

2번 보다는 1번이 더 좋을 것 같구요

요약하면, Helm chart 의 values.yaml 에 적혀 있는 값은
결국 K8s 컨테이너에는 env var 로 적용된다는 것입니다.


위의 사유로,
store_conf.yaml 을 통해 설정하도록 되어 있는 설정값들을
env var 를 통해 설정하도록 변경하는 것이 어떨까 하여 이슈를 작성합니다.

(Spider, TB 등을 컨테이너로 띄울 때
nutsdb 대신 etcd를 사용하려고 하니
해당 설정값이 yaml 파일 안에 있어서.. 발생한 사안입니다.)

Ref: @powerkimhub @seokho-son

Update needed: nutsdb updated

  • CB-Store version: Thu Feb 6 10:33:15 2020 +0900
commit 183d4e691c9f82227ca2f32a59405ffc2fa44513 (HEAD -> master, origin/master, origin/HEAD)
Merge: 199fcad cd85997
Author: ByoungSeob Kim <[email protected]>
Date:   Thu Feb 6 10:33:15 2020 +0900

    Merge pull request #9 from jihoon-seo/200206-remove-go-mod-file
    
    Remove go.mod file
  • To reproduce the error:
    source setup.env
    cd test
    go run test.go

  • Occurred error:

# github.com/cloud-barista/cb-store/store-drivers/nutsdb-driver
/root/go/src/github.com/cloud-barista/cb-store/store-drivers/nutsdb-driver/nutsdb-driver.go:170:38: assignment mismatch: 2 variables but 3 values
/root/go/src/github.com/cloud-barista/cb-store/store-drivers/nutsdb-driver/nutsdb-driver.go:170:54: not enough arguments in call to tx.PrefixScan
        have (string, []byte, number)
        want (string, []byte, int, int)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.