mirror of
https://github.com/HDT3213/godis.git
synced 2025-10-05 00:42:43 +08:00
optimize project structure
This commit is contained in:
29
README.md
29
README.md
@@ -126,22 +126,22 @@ MSET (10 keys): 65487.89 requests per second
|
||||
|
||||
If you want to read my code in this repository, here is a simple guidance.
|
||||
|
||||
- github.com/hdt3213/godis/cmd: only the entry point
|
||||
- github.com/hdt3213/godis/config: config parser
|
||||
- github.com/hdt3213/godis/interface: some interface definitions
|
||||
- github.com/hdt3213/godis/lib: some utils, such as logger, sync utils and wildcard
|
||||
- project root: only the entry point
|
||||
- config: config parser
|
||||
- interface: some interface definitions
|
||||
- lib: some utils, such as logger, sync utils and wildcard
|
||||
|
||||
I suggest focusing on the following directories:
|
||||
|
||||
- github.com/hdt3213/godis/tcp: the tcp server
|
||||
- github.com/hdt3213/godis/redis: the redis protocol parser
|
||||
- github.com/hdt3213/godis/datastruct: the implements of data structures
|
||||
- tcp: the tcp server
|
||||
- redis: the redis protocol parser
|
||||
- datastruct: the implements of data structures
|
||||
- dict: a concurrent hash map
|
||||
- list: a linked list
|
||||
- lock: it is used to lock keys to ensure thread safety
|
||||
- set: a hash set based on map
|
||||
- sortedset: a sorted set implements based on skiplist
|
||||
- github.com/hdt3213/godis: the core of storage engine
|
||||
- database: the core of storage engine
|
||||
- server.go: a standalone redis server,
|
||||
- db.go: the basement function of database
|
||||
- exec.go: the gateway of database
|
||||
@@ -155,6 +155,19 @@ I suggest focusing on the following directories:
|
||||
- pubsub.go: implements of publish / subscribe
|
||||
- aof.go: implements of AOF persistence and rewrite
|
||||
- geo.go: implements of geography features
|
||||
- sys.go: authentication and other system function
|
||||
- transaction.go: local transaction
|
||||
- cluster: 集群
|
||||
- cluster.go: entrance of cluster mode
|
||||
- com.go: communication within nodes
|
||||
- del.go: atomic implementation of `delete` command in cluster
|
||||
- keys.go: keys command
|
||||
- mset.go: atomic implementation of `mset` command in cluster
|
||||
- multi.go: entrance of distributed transaction
|
||||
- pubsub.go: pub/sub in cluster
|
||||
- rename.go: `rename` command in cluster
|
||||
- tcc.go: try-commit-catch distributed transaction implementation
|
||||
- aof: AOF persistence
|
||||
|
||||
# License
|
||||
|
||||
|
31
README_CN.md
31
README_CN.md
@@ -116,22 +116,22 @@ MSET (10 keys): 65487.89 requests per second
|
||||
|
||||
本项目的目录结构:
|
||||
|
||||
- github.com/hdt3213/godis/cmd: main 函数,执行入口
|
||||
- github.com/hdt3213/godis/config: 配置文件解析
|
||||
- github.com/hdt3213/godis/interface: 一些模块间的接口定义
|
||||
- github.com/hdt3213/godis/lib: 各种工具,比如logger、同步和通配符
|
||||
- 根目录: main 函数,执行入口
|
||||
- config: 配置文件解析
|
||||
- interface: 一些模块间的接口定义
|
||||
- lib: 各种工具,比如logger、同步和通配符
|
||||
|
||||
建议按照下列顺序阅读各包:
|
||||
|
||||
- github.com/hdt3213/godis/tcp: tcp 服务器实现
|
||||
- github.com/hdt3213/godis/redis: redis 协议解析器
|
||||
- github.com/hdt3213/godis/datastruct: redis 的各类数据结构实现
|
||||
- tcp: tcp 服务器实现
|
||||
- redis: redis 协议解析器
|
||||
- datastruct: redis 的各类数据结构实现
|
||||
- dict: hash 表
|
||||
- list: 链表
|
||||
- lock: 用于锁定 key 的锁组件
|
||||
- set: 基于hash表的集合
|
||||
- sortedset: 基于跳表实现的有序集合
|
||||
- github.com/hdt3213/godis: 存储引擎核心
|
||||
- database: 存储引擎核心
|
||||
- db.go: 引擎的基础功能
|
||||
- router.go: 将命令路由给响应的处理函数
|
||||
- keys.go: del、ttl、expire 等通用命令实现
|
||||
@@ -141,4 +141,17 @@ MSET (10 keys): 65487.89 requests per second
|
||||
- set.go: sadd 等集合命令实现
|
||||
- sortedset.go: zadd 等有序集合命令实现
|
||||
- pubsub.go: 发布订阅命令实现
|
||||
- aof.go: aof持久化实现
|
||||
- geo.go: GEO 相关命令实现
|
||||
- sys.go: Auth 等系统功能实现
|
||||
- transaction.go: 单机事务实现
|
||||
- cluster: 集群
|
||||
- cluster.go: 集群入口
|
||||
- com.go: 节点间通信
|
||||
- del.go: delete 命令原子性实现
|
||||
- keys.go: key 相关命令集群中实现
|
||||
- mset.go: mset 命令原子性实现
|
||||
- multi.go: 集群内事务实现
|
||||
- pubsub.go: 发布订阅实现
|
||||
- rename.go: rename 命令集群实现
|
||||
- tcc.go: tcc 分布式事务底层实现
|
||||
- aof: AOF 持久化实现
|
@@ -1,3 +1,3 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
go build -o target/godis-darwin ./cmd
|
||||
go build -o target/godis-darwin ./
|
||||
|
@@ -1,3 +1,3 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o target/godis-linux ./cmd
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o target/godis-linux ./
|
@@ -4,8 +4,8 @@ package cluster
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/hdt3213/godis"
|
||||
"github.com/hdt3213/godis/config"
|
||||
database2 "github.com/hdt3213/godis/database"
|
||||
"github.com/hdt3213/godis/datastruct/dict"
|
||||
"github.com/hdt3213/godis/interface/database"
|
||||
"github.com/hdt3213/godis/interface/redis"
|
||||
@@ -47,7 +47,7 @@ func MakeCluster() *Cluster {
|
||||
cluster := &Cluster{
|
||||
self: config.Properties.Self,
|
||||
|
||||
db: godis.NewStandaloneServer(),
|
||||
db: database2.NewStandaloneServer(),
|
||||
transactions: dict.MakeSimple(),
|
||||
peerPicker: consistenthash.New(replicas, nil),
|
||||
peerConnection: make(map[string]*pool.ObjectPool),
|
||||
@@ -102,7 +102,7 @@ func (cluster *Cluster) Exec(c redis.Connection, cmdLine [][]byte) (result redis
|
||||
}()
|
||||
cmdName := strings.ToLower(string(cmdLine[0]))
|
||||
if cmdName == "auth" {
|
||||
return godis.Auth(c, cmdLine[1:])
|
||||
return database2.Auth(c, cmdLine[1:])
|
||||
}
|
||||
if !isAuthenticated(c) {
|
||||
return reply.MakeErrReply("NOAUTH Authentication required")
|
||||
@@ -112,12 +112,12 @@ func (cluster *Cluster) Exec(c redis.Connection, cmdLine [][]byte) (result redis
|
||||
if len(cmdLine) != 1 {
|
||||
return reply.MakeArgNumErrReply(cmdName)
|
||||
}
|
||||
return godis.StartMulti(c)
|
||||
return database2.StartMulti(c)
|
||||
} else if cmdName == "discard" {
|
||||
if len(cmdLine) != 1 {
|
||||
return reply.MakeArgNumErrReply(cmdName)
|
||||
}
|
||||
return godis.DiscardMulti(c)
|
||||
return database2.DiscardMulti(c)
|
||||
} else if cmdName == "exec" {
|
||||
if len(cmdLine) != 1 {
|
||||
return reply.MakeArgNumErrReply(cmdName)
|
||||
@@ -130,7 +130,7 @@ func (cluster *Cluster) Exec(c redis.Connection, cmdLine [][]byte) (result redis
|
||||
return execSelect(c, cmdLine)
|
||||
}
|
||||
if c != nil && c.InMultiState() {
|
||||
return godis.EnqueueCmd(c, cmdLine)
|
||||
return database2.EnqueueCmd(c, cmdLine)
|
||||
}
|
||||
cmdFunc, ok := router[cmdName]
|
||||
if !ok {
|
||||
|
@@ -1,7 +1,7 @@
|
||||
package cluster
|
||||
|
||||
import (
|
||||
"github.com/hdt3213/godis"
|
||||
"github.com/hdt3213/godis/database"
|
||||
"github.com/hdt3213/godis/interface/redis"
|
||||
"github.com/hdt3213/godis/lib/utils"
|
||||
"github.com/hdt3213/godis/redis/reply"
|
||||
@@ -24,7 +24,7 @@ func execMulti(cluster *Cluster, conn redis.Connection, cmdLine CmdLine) redis.R
|
||||
// analysis related keys
|
||||
keys := make([]string, 0) // may contains duplicate
|
||||
for _, cl := range cmdLines {
|
||||
wKeys, rKeys := godis.GetRelatedKeys(cl)
|
||||
wKeys, rKeys := database.GetRelatedKeys(cl)
|
||||
keys = append(keys, wKeys...)
|
||||
keys = append(keys, rKeys...)
|
||||
}
|
||||
|
@@ -2,7 +2,7 @@ package cluster
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/hdt3213/godis"
|
||||
"github.com/hdt3213/godis/database"
|
||||
"github.com/hdt3213/godis/interface/redis"
|
||||
"github.com/hdt3213/godis/lib/logger"
|
||||
"github.com/hdt3213/godis/lib/timewheel"
|
||||
@@ -77,7 +77,7 @@ func (tx *Transaction) prepare() error {
|
||||
tx.mu.Lock()
|
||||
defer tx.mu.Unlock()
|
||||
|
||||
tx.writeKeys, tx.readKeys = godis.GetRelatedKeys(tx.cmdLine)
|
||||
tx.writeKeys, tx.readKeys = database.GetRelatedKeys(tx.cmdLine)
|
||||
// lock writeKeys
|
||||
tx.lockKeys()
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
package godis
|
||||
package database
|
||||
|
||||
import (
|
||||
"github.com/hdt3213/godis/config"
|
@@ -1,5 +1,5 @@
|
||||
// Package godis is a memory database with redis compatible interface
|
||||
package godis
|
||||
package database
|
||||
|
||||
import (
|
||||
"github.com/hdt3213/godis/datastruct/dict"
|
@@ -1,4 +1,4 @@
|
||||
package godis
|
||||
package database
|
||||
|
||||
import (
|
||||
"fmt"
|
@@ -1,4 +1,4 @@
|
||||
package godis
|
||||
package database
|
||||
|
||||
import (
|
||||
"fmt"
|
@@ -1,4 +1,4 @@
|
||||
package godis
|
||||
package database
|
||||
|
||||
import (
|
||||
Dict "github.com/hdt3213/godis/datastruct/dict"
|
@@ -1,4 +1,4 @@
|
||||
package godis
|
||||
package database
|
||||
|
||||
import (
|
||||
"fmt"
|
@@ -1,4 +1,4 @@
|
||||
package godis
|
||||
package database
|
||||
|
||||
import (
|
||||
"github.com/hdt3213/godis/aof"
|
@@ -1,4 +1,4 @@
|
||||
package godis
|
||||
package database
|
||||
|
||||
import (
|
||||
"fmt"
|
@@ -1,4 +1,4 @@
|
||||
package godis
|
||||
package database
|
||||
|
||||
import (
|
||||
List "github.com/hdt3213/godis/datastruct/list"
|
@@ -1,4 +1,4 @@
|
||||
package godis
|
||||
package database
|
||||
|
||||
import (
|
||||
"fmt"
|
@@ -1,4 +1,4 @@
|
||||
package godis
|
||||
package database
|
||||
|
||||
import (
|
||||
"strings"
|
@@ -1,4 +1,4 @@
|
||||
package godis
|
||||
package database
|
||||
|
||||
import (
|
||||
"fmt"
|
@@ -1,4 +1,4 @@
|
||||
package godis
|
||||
package database
|
||||
|
||||
import (
|
||||
HashSet "github.com/hdt3213/godis/datastruct/set"
|
@@ -1,4 +1,4 @@
|
||||
package godis
|
||||
package database
|
||||
|
||||
import (
|
||||
"fmt"
|
@@ -1,4 +1,4 @@
|
||||
package godis
|
||||
package database
|
||||
|
||||
import (
|
||||
SortedSet "github.com/hdt3213/godis/datastruct/sortedset"
|
@@ -1,4 +1,4 @@
|
||||
package godis
|
||||
package database
|
||||
|
||||
import (
|
||||
"github.com/hdt3213/godis/lib/utils"
|
@@ -1,4 +1,4 @@
|
||||
package godis
|
||||
package database
|
||||
|
||||
import (
|
||||
"github.com/hdt3213/godis/aof"
|
@@ -1,4 +1,4 @@
|
||||
package godis
|
||||
package database
|
||||
|
||||
import (
|
||||
"fmt"
|
@@ -1,4 +1,4 @@
|
||||
package godis
|
||||
package database
|
||||
|
||||
import (
|
||||
"github.com/hdt3213/godis/config"
|
@@ -1,4 +1,4 @@
|
||||
package godis
|
||||
package database
|
||||
|
||||
import (
|
||||
"github.com/hdt3213/godis/config"
|
@@ -1,4 +1,4 @@
|
||||
package godis
|
||||
package database
|
||||
|
||||
import (
|
||||
"github.com/hdt3213/godis/datastruct/set"
|
@@ -1,4 +1,4 @@
|
||||
package godis
|
||||
package database
|
||||
|
||||
import (
|
||||
"github.com/hdt3213/godis/lib/utils"
|
@@ -1,4 +1,4 @@
|
||||
package godis
|
||||
package database
|
||||
|
||||
import (
|
||||
"github.com/hdt3213/godis/aof"
|
@@ -1,4 +1,4 @@
|
||||
package godis
|
||||
package database
|
||||
|
||||
import (
|
||||
"github.com/hdt3213/godis/lib/utils"
|
@@ -1,4 +1,4 @@
|
||||
package godis
|
||||
package database
|
||||
|
||||
import (
|
||||
"github.com/hdt3213/godis/datastruct/dict"
|
@@ -6,9 +6,9 @@ package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/hdt3213/godis"
|
||||
"github.com/hdt3213/godis/cluster"
|
||||
"github.com/hdt3213/godis/config"
|
||||
database2 "github.com/hdt3213/godis/database"
|
||||
"github.com/hdt3213/godis/interface/database"
|
||||
"github.com/hdt3213/godis/lib/logger"
|
||||
"github.com/hdt3213/godis/lib/sync/atomic"
|
||||
@@ -39,7 +39,7 @@ func MakeHandler() *Handler {
|
||||
len(config.Properties.Peers) > 0 {
|
||||
db = cluster.MakeCluster()
|
||||
} else {
|
||||
db = godis.NewStandaloneServer()
|
||||
db = database2.NewStandaloneServer()
|
||||
}
|
||||
return &Handler{
|
||||
db: db,
|
||||
|
Reference in New Issue
Block a user