mirror of
https://github.com/zrepl/zrepl.git
synced 2024-12-23 15:38:49 +01:00
35dcfc234e
Pushing is achieved by inverting the roles on the established connection, i.e. the client tells the server what data it should pull from the client (PullMeRequest). Role inversion is achieved by moving the server loop to the serverLoop function of ByteStreamRPC, which can be called from both the Listen() function (server-side) and the PullMeRequest() client-side function. A donwside of this PullMe approach is that the replication policies become part of the rpc, because the puller must follow the policy.
113 lines
2.4 KiB
Go
113 lines
2.4 KiB
Go
package rpc
|
|
|
|
import "io"
|
|
import "github.com/zrepl/zrepl/zfs"
|
|
|
|
type RequestId [16]byte
|
|
type RequestType uint8
|
|
|
|
const (
|
|
RTProtocolVersionRequest RequestType = 0x01
|
|
RTFilesystemRequest = 0x10
|
|
RTFilesystemVersionsRequest = 0x11
|
|
RTInitialTransferRequest = 0x12
|
|
RTIncrementalTransferRequest = 0x13
|
|
RTPullMeRequest = 0x20
|
|
RTCloseRequest = 0xf0
|
|
)
|
|
|
|
type RequestHeader struct {
|
|
Type RequestType
|
|
Id [16]byte // UUID
|
|
}
|
|
|
|
type FilesystemRequest struct {
|
|
Roots []string // may be nil, indicating interest in all filesystems
|
|
}
|
|
|
|
type FilesystemVersionsRequest struct {
|
|
Filesystem zfs.DatasetPath
|
|
}
|
|
|
|
type InitialTransferRequest struct {
|
|
Filesystem zfs.DatasetPath
|
|
FilesystemVersion zfs.FilesystemVersion
|
|
}
|
|
|
|
func (r InitialTransferRequest) Respond(snapshotReader io.Reader) {
|
|
|
|
}
|
|
|
|
type IncrementalTransferRequest struct {
|
|
Filesystem zfs.DatasetPath
|
|
From zfs.FilesystemVersion
|
|
To zfs.FilesystemVersion
|
|
}
|
|
|
|
func (r IncrementalTransferRequest) Respond(snapshotReader io.Reader) {
|
|
|
|
}
|
|
|
|
type ByteStreamRPCProtocolVersionRequest struct {
|
|
ClientVersion uint8
|
|
}
|
|
|
|
const LOCAL_TRANSPORT_IDENTITY string = "local"
|
|
|
|
const DEFAULT_INITIAL_REPL_POLICY = InitialReplPolicyMostRecent
|
|
|
|
type InitialReplPolicy string
|
|
|
|
const (
|
|
InitialReplPolicyMostRecent InitialReplPolicy = "most_recent"
|
|
InitialReplPolicyAll InitialReplPolicy = "all"
|
|
)
|
|
|
|
type PullMeRequest struct {
|
|
// if true, the other fields are undefined
|
|
Finished bool
|
|
InitialReplPolicy InitialReplPolicy
|
|
}
|
|
|
|
type CloseRequest struct {
|
|
Goodbye string
|
|
}
|
|
|
|
type ErrorId uint8
|
|
|
|
const (
|
|
ENoError ErrorId = 0
|
|
EDecodeHeader = 1
|
|
EUnknownRequestType = 2
|
|
EDecodeRequestBody = 3
|
|
EProtocolVersionMismatch = 4
|
|
EHandler = 5
|
|
)
|
|
|
|
type ResponseType uint8
|
|
|
|
const (
|
|
RNONE ResponseType = 0x0
|
|
ROK = 0x1
|
|
RFilesystems = 0x10
|
|
RFilesystemDiff = 0x11
|
|
RChunkedStream = 0x20
|
|
)
|
|
|
|
type ResponseHeader struct {
|
|
RequestId RequestId
|
|
ErrorId ErrorId
|
|
Message string
|
|
ResponseType ResponseType
|
|
}
|
|
|
|
func NewByteStreamRPCProtocolVersionRequest() ByteStreamRPCProtocolVersionRequest {
|
|
return ByteStreamRPCProtocolVersionRequest{
|
|
ClientVersion: ByteStreamRPCProtocolVersion,
|
|
}
|
|
}
|
|
|
|
func newUUID() [16]byte {
|
|
return [16]byte{}
|
|
}
|