mirror of
https://github.com/wavetermdev/backup.git
synced 2026-08-05 13:57:07 -07:00
update statediff algorithm for wavesrv / remote instances (#530)
* remote statemap from waveshell server (diff against initial state) * move ShellStatePtr from sstore to packet so it can be passed over the wire * add finalstatebaseptr to cmddone * much improved diff computation code on wavesrv side * fix displayname -- now using hash * add comments, change a couple msh.WriteToPtyBuffer calls to log.Printfs
This commit is contained in:
@@ -793,7 +793,7 @@ func UpdateCmdDoneInfo(ctx context.Context, update *scbus.ModelUpdatePacketType,
|
||||
return nil
|
||||
}
|
||||
|
||||
func UpdateCmdRtnState(ctx context.Context, ck base.CommandKey, statePtr ShellStatePtr) error {
|
||||
func UpdateCmdRtnState(ctx context.Context, ck base.CommandKey, statePtr packet.ShellStatePtr) error {
|
||||
if ck.IsEmpty() {
|
||||
return fmt.Errorf("cannot update cmdrtnstate, empty ck")
|
||||
}
|
||||
@@ -1098,7 +1098,7 @@ func DeleteScreen(ctx context.Context, screenId string, sessionDel bool, update
|
||||
return update, nil
|
||||
}
|
||||
|
||||
func GetRemoteState(ctx context.Context, sessionId string, screenId string, remotePtr RemotePtrType) (*packet.ShellState, *ShellStatePtr, error) {
|
||||
func GetRemoteState(ctx context.Context, sessionId string, screenId string, remotePtr RemotePtrType) (*packet.ShellState, *packet.ShellStatePtr, error) {
|
||||
ssptr, err := GetRemoteStatePtr(ctx, sessionId, screenId, remotePtr)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
@@ -1113,8 +1113,8 @@ func GetRemoteState(ctx context.Context, sessionId string, screenId string, remo
|
||||
return state, ssptr, err
|
||||
}
|
||||
|
||||
func GetRemoteStatePtr(ctx context.Context, sessionId string, screenId string, remotePtr RemotePtrType) (*ShellStatePtr, error) {
|
||||
var ssptr *ShellStatePtr
|
||||
func GetRemoteStatePtr(ctx context.Context, sessionId string, screenId string, remotePtr RemotePtrType) (*packet.ShellStatePtr, error) {
|
||||
var ssptr *packet.ShellStatePtr
|
||||
txErr := WithTx(ctx, func(tx *TxWrap) error {
|
||||
ri, err := GetRemoteInstance(tx.Context(), sessionId, screenId, remotePtr)
|
||||
if err != nil {
|
||||
@@ -1123,7 +1123,7 @@ func GetRemoteStatePtr(ctx context.Context, sessionId string, screenId string, r
|
||||
if ri == nil {
|
||||
return nil
|
||||
}
|
||||
ssptr = &ShellStatePtr{ri.StateBaseHash, ri.StateDiffHashArr}
|
||||
ssptr = &packet.ShellStatePtr{ri.StateBaseHash, ri.StateDiffHashArr}
|
||||
return nil
|
||||
})
|
||||
if txErr != nil {
|
||||
@@ -1836,7 +1836,7 @@ func GetStateBaseVersion(ctx context.Context, baseHash string) (string, error) {
|
||||
})
|
||||
}
|
||||
|
||||
func GetCurStateDiffFromPtr(ctx context.Context, ssPtr *ShellStatePtr) (*packet.ShellStateDiff, error) {
|
||||
func GetCurStateDiffFromPtr(ctx context.Context, ssPtr *packet.ShellStatePtr) (*packet.ShellStateDiff, error) {
|
||||
if ssPtr == nil {
|
||||
return nil, fmt.Errorf("cannot resolve state, empty stateptr")
|
||||
}
|
||||
@@ -1894,7 +1894,7 @@ func GetStateDiff(ctx context.Context, diffHash string) (*packet.ShellStateDiff,
|
||||
}
|
||||
|
||||
// returns error when not found
|
||||
func GetFullState(ctx context.Context, ssPtr ShellStatePtr) (*packet.ShellState, error) {
|
||||
func GetFullState(ctx context.Context, ssPtr packet.ShellStatePtr) (*packet.ShellState, error) {
|
||||
var state *packet.ShellState
|
||||
if ssPtr.BaseHash == "" {
|
||||
return nil, fmt.Errorf("invalid empty basehash")
|
||||
|
||||
@@ -538,18 +538,6 @@ func (opts TermOpts) Value() (driver.Value, error) {
|
||||
return quickValueJson(opts)
|
||||
}
|
||||
|
||||
type ShellStatePtr struct {
|
||||
BaseHash string
|
||||
DiffHashArr []string
|
||||
}
|
||||
|
||||
func (ssptr *ShellStatePtr) IsEmpty() bool {
|
||||
if ssptr == nil || ssptr.BaseHash == "" {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
type RemoteInstance struct {
|
||||
RIId string `json:"riid"`
|
||||
Name string `json:"name"`
|
||||
@@ -864,27 +852,27 @@ func (r *RemoteType) GetName() string {
|
||||
}
|
||||
|
||||
type CmdType struct {
|
||||
ScreenId string `json:"screenid"`
|
||||
LineId string `json:"lineid"`
|
||||
Remote RemotePtrType `json:"remote"`
|
||||
CmdStr string `json:"cmdstr"`
|
||||
RawCmdStr string `json:"rawcmdstr"`
|
||||
FeState map[string]string `json:"festate"`
|
||||
StatePtr ShellStatePtr `json:"state"`
|
||||
TermOpts TermOpts `json:"termopts"`
|
||||
OrigTermOpts TermOpts `json:"origtermopts"`
|
||||
Status string `json:"status"`
|
||||
CmdPid int `json:"cmdpid"`
|
||||
RemotePid int `json:"remotepid"`
|
||||
RestartTs int64 `json:"restartts,omitempty"`
|
||||
DoneTs int64 `json:"donets"`
|
||||
ExitCode int `json:"exitcode"`
|
||||
DurationMs int `json:"durationms"`
|
||||
RunOut []packet.PacketType `json:"runout,omitempty"`
|
||||
RtnState bool `json:"rtnstate,omitempty"`
|
||||
RtnStatePtr ShellStatePtr `json:"rtnstateptr,omitempty"`
|
||||
Remove bool `json:"remove,omitempty"` // not persisted to DB
|
||||
Restarted bool `json:"restarted,omitempty"` // not persisted to DB
|
||||
ScreenId string `json:"screenid"`
|
||||
LineId string `json:"lineid"`
|
||||
Remote RemotePtrType `json:"remote"`
|
||||
CmdStr string `json:"cmdstr"`
|
||||
RawCmdStr string `json:"rawcmdstr"`
|
||||
FeState map[string]string `json:"festate"`
|
||||
StatePtr packet.ShellStatePtr `json:"state"`
|
||||
TermOpts TermOpts `json:"termopts"`
|
||||
OrigTermOpts TermOpts `json:"origtermopts"`
|
||||
Status string `json:"status"`
|
||||
CmdPid int `json:"cmdpid"`
|
||||
RemotePid int `json:"remotepid"`
|
||||
RestartTs int64 `json:"restartts,omitempty"`
|
||||
DoneTs int64 `json:"donets"`
|
||||
ExitCode int `json:"exitcode"`
|
||||
DurationMs int `json:"durationms"`
|
||||
RunOut []packet.PacketType `json:"runout,omitempty"`
|
||||
RtnState bool `json:"rtnstate,omitempty"`
|
||||
RtnStatePtr packet.ShellStatePtr `json:"rtnstateptr,omitempty"`
|
||||
Remove bool `json:"remove,omitempty"` // not persisted to DB
|
||||
Restarted bool `json:"restarted,omitempty"` // not persisted to DB
|
||||
}
|
||||
|
||||
func (CmdType) GetType() string {
|
||||
|
||||
Reference in New Issue
Block a user