感动中国
This commit is contained in:
@@ -119,7 +119,7 @@ func StartNode(ServerID uint64, serverconfigs []*autoconfig.ConfigServer, gdb *g
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if err := nh.StartReplica(initialMembers, false, NewFsStateMachine, rc); err != nil {
|
||||
if err := nh.StartReplica(initialMembers, true, NewFsStateMachine, rc); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "failed to add cluster, %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
@@ -186,6 +186,7 @@ func StartNodeEx(ServerID uint64, serverconfigs []*autoconfig.ConfigServer, gdb
|
||||
|
||||
CompactionOverhead: 5,
|
||||
}
|
||||
|
||||
datadir := filepath.Join(
|
||||
"shared-state",
|
||||
fmt.Sprintf("node%d", ServerID))
|
||||
@@ -203,6 +204,7 @@ func StartNodeEx(ServerID uint64, serverconfigs []*autoconfig.ConfigServer, gdb
|
||||
// RaftAddress is used to identify the NodeHost instance
|
||||
RaftAddress: nodeAddr,
|
||||
}
|
||||
|
||||
nh, err := dragonboat.NewNodeHost(nhc)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
||||
@@ -2,9 +2,13 @@ package shared
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/utils/auth"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/lni/dragonboat/v4"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type SharedState struct {
|
||||
@@ -13,6 +17,23 @@ type SharedState struct {
|
||||
nh *dragonboat.NodeHost
|
||||
}
|
||||
|
||||
func GetUserState(UserId int64, gdb *gorm.DB) (us *UserState, err error) {
|
||||
models := gmodel.NewAllModels(gdb)
|
||||
user, err := models.FsUser.FindUserById(context.TODO(), UserId)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
userState := &UserState{
|
||||
UserId: UserId,
|
||||
PwdHash: auth.StringToHash(*user.PasswordHash),
|
||||
UpdateAt: time.Now(),
|
||||
}
|
||||
|
||||
return userState, nil
|
||||
}
|
||||
|
||||
func (ss *SharedState) GetUserState(Userid int64) (us *UserState, err error) {
|
||||
|
||||
ius, err := ss.nh.SyncRead(context.TODO(), ss.shardID, Userid)
|
||||
|
||||
Reference in New Issue
Block a user