mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-12-01 15:59:01 +08:00
68d39c86f1
The exisitng key-value operation for stores using mysql, postgres, and maybe cassandra are already broken. The kv is used to store hardlink, filer store signature and replication progress. So users using hardlink and also uses mysql, postgres, or cassandra will have broken hard links. Users using filer.sync will need to re-sync the files.
63 lines
1.4 KiB
Go
63 lines
1.4 KiB
Go
package cassandra
|
|
|
|
import (
|
|
"context"
|
|
"encoding/base64"
|
|
"fmt"
|
|
"github.com/chrislusf/seaweedfs/weed/filer"
|
|
"github.com/gocql/gocql"
|
|
)
|
|
|
|
func (store *CassandraStore) KvPut(ctx context.Context, key []byte, value []byte) (err error) {
|
|
dir, name := genDirAndName(key)
|
|
|
|
if err := store.session.Query(
|
|
"INSERT INTO filemeta (directory,name,meta) VALUES(?,?,?) USING TTL ? ",
|
|
dir, name, value, 0).Exec(); err != nil {
|
|
return fmt.Errorf("kv insert: %s", err)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (store *CassandraStore) KvGet(ctx context.Context, key []byte) (data []byte, err error) {
|
|
dir, name := genDirAndName(key)
|
|
|
|
if err := store.session.Query(
|
|
"SELECT meta FROM filemeta WHERE directory=? AND name=?",
|
|
dir, name).Consistency(gocql.One).Scan(&data); err != nil {
|
|
if err != gocql.ErrNotFound {
|
|
return nil, filer.ErrKvNotFound
|
|
}
|
|
}
|
|
|
|
if len(data) == 0 {
|
|
return nil, filer.ErrKvNotFound
|
|
}
|
|
|
|
return data, nil
|
|
}
|
|
|
|
func (store *CassandraStore) KvDelete(ctx context.Context, key []byte) (err error) {
|
|
dir, name := genDirAndName(key)
|
|
|
|
if err := store.session.Query(
|
|
"DELETE FROM filemeta WHERE directory=? AND name=?",
|
|
dir, name).Exec(); err != nil {
|
|
return fmt.Errorf("kv delete: %v", err)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func genDirAndName(key []byte) (dir string, name string) {
|
|
for len(key) < 8 {
|
|
key = append(key, 0)
|
|
}
|
|
|
|
dir = base64.StdEncoding.EncodeToString(key[:8])
|
|
name = base64.StdEncoding.EncodeToString(key[8:])
|
|
|
|
return
|
|
}
|