diff --git a/endpoint/endpoint.go b/endpoint/endpoint.go index 3670069..a928d80 100644 --- a/endpoint/endpoint.go +++ b/endpoint/endpoint.go @@ -48,9 +48,10 @@ func (s *Sender) ListFilesystems(ctx context.Context, r *pdu.ListFilesystemReq) rfss[i] = &pdu.Filesystem{ Path: fss[i].ToString(), // FIXME: not supporting ResumeToken yet + IsPlaceholder: false, // sender FSs are never placeholders } } - res := &pdu.ListFilesystemRes{Filesystems: rfss, Empty: len(rfss) == 0} + res := &pdu.ListFilesystemRes{Filesystems: rfss} return res, nil } @@ -118,7 +119,7 @@ func (p *Sender) PingDataconn(ctx context.Context, req *pdu.PingReq) (*pdu.PingR return p.Ping(ctx, req) } -func (p *Sender) WaitForConnectivity(ctx context.Context) (error) { +func (p *Sender) WaitForConnectivity(ctx context.Context) error { return nil } @@ -243,7 +244,7 @@ func (s *Receiver) ListFilesystems(ctx context.Context, req *pdu.ListFilesystemR if err != nil { return nil, err } - // present without prefix, and only those that are not placeholders + // present filesystem without the root_fs prefix fss := make([]*pdu.Filesystem, 0, len(filtered)) for _, a := range filtered { ph, err := zfs.ZFSIsPlaceholderFilesystem(a) @@ -254,21 +255,16 @@ func (s *Receiver) ListFilesystems(ctx context.Context, req *pdu.ListFilesystemR Error("inconsistent placeholder property") return nil, errors.New("server error: inconsistent placeholder property") // don't leak path } - if ph { - getLogger(ctx). - WithField("fs", a.ToString()). - Debug("ignoring placeholder filesystem") - continue - } getLogger(ctx). WithField("fs", a.ToString()). - Debug("non-placeholder filesystem") + WithField("is_placeholder", ph). + Debug("filesystem") a.TrimPrefix(root) - fss = append(fss, &pdu.Filesystem{Path: a.ToString()}) + fss = append(fss, &pdu.Filesystem{Path: a.ToString(), IsPlaceholder: ph}) } if len(fss) == 0 { - getLogger(ctx).Debug("no non-placeholder filesystems") - return &pdu.ListFilesystemRes{Empty: true}, nil + getLogger(ctx).Debug("no filesystems found") + return &pdu.ListFilesystemRes{}, nil } return &pdu.ListFilesystemRes{Filesystems: fss}, nil } @@ -304,7 +300,7 @@ func (s *Receiver) PingDataconn(ctx context.Context, req *pdu.PingReq) (*pdu.Pin return s.Ping(ctx, req) } -func (s *Receiver) WaitForConnectivity(ctx context.Context) (error) { +func (s *Receiver) WaitForConnectivity(ctx context.Context) error { return nil } @@ -316,7 +312,6 @@ func (s *Receiver) Send(ctx context.Context, req *pdu.SendReq) (*pdu.SendRes, zf return nil, nil, fmt.Errorf("receiver does not implement Send()") } - func (s *Receiver) Receive(ctx context.Context, req *pdu.ReceiveReq, receive zfs.StreamCopier) (*pdu.ReceiveRes, error) { getLogger(ctx).Debug("incoming Receive") defer receive.Close() @@ -357,25 +352,27 @@ func (s *Receiver) Receive(ctx context.Context, req *pdu.ReceiveReq, receive zfs return nil, err } - needForceRecv := false + var clearPlaceholderProperty bool + var recvOpts zfs.RecvOptions props, err := zfs.ZFSGet(lp, []string{zfs.ZREPL_PLACEHOLDER_PROPERTY_NAME}) if err == nil { if isPlaceholder, _ := zfs.IsPlaceholder(lp, props.Get(zfs.ZREPL_PLACEHOLDER_PROPERTY_NAME)); isPlaceholder { - needForceRecv = true + recvOpts.RollbackAndForceRecv = true + clearPlaceholderProperty = true + } + } + if clearPlaceholderProperty { + if err := zfs.ZFSSetNoPlaceholder(lp); err != nil { + return nil, fmt.Errorf("cannot clear placeholder property for forced receive: %s", err) } } - args := make([]string, 0, 1) - if needForceRecv { - args = append(args, "-F") - } + getLogger(ctx).WithField("opts", fmt.Sprintf("%#v", recvOpts)).Debug("start receive command") - getLogger(ctx).Debug("start receive command") - - if err := zfs.ZFSRecv(ctx, lp.ToString(), receive, args...); err != nil { + if err := zfs.ZFSRecv(ctx, lp.ToString(), receive, recvOpts); err != nil { getLogger(ctx). WithError(err). - WithField("args", args). + WithField("opts", recvOpts). Error("zfs receive failed") return nil, err } diff --git a/replication/logic/pdu/pdu.pb.go b/replication/logic/pdu/pdu.pb.go index 4424597..b783f3d 100644 --- a/replication/logic/pdu/pdu.pb.go +++ b/replication/logic/pdu/pdu.pb.go @@ -43,7 +43,7 @@ func (x FilesystemVersion_VersionType) String() string { return proto.EnumName(FilesystemVersion_VersionType_name, int32(x)) } func (FilesystemVersion_VersionType) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_pdu_759e477f62b58e58, []int{5, 0} + return fileDescriptor_pdu_83b7e2a28d820622, []int{5, 0} } type ListFilesystemReq struct { @@ -56,7 +56,7 @@ func (m *ListFilesystemReq) Reset() { *m = ListFilesystemReq{} } func (m *ListFilesystemReq) String() string { return proto.CompactTextString(m) } func (*ListFilesystemReq) ProtoMessage() {} func (*ListFilesystemReq) Descriptor() ([]byte, []int) { - return fileDescriptor_pdu_759e477f62b58e58, []int{0} + return fileDescriptor_pdu_83b7e2a28d820622, []int{0} } func (m *ListFilesystemReq) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_ListFilesystemReq.Unmarshal(m, b) @@ -78,7 +78,6 @@ var xxx_messageInfo_ListFilesystemReq proto.InternalMessageInfo type ListFilesystemRes struct { Filesystems []*Filesystem `protobuf:"bytes,1,rep,name=Filesystems,proto3" json:"Filesystems,omitempty"` - Empty bool `protobuf:"varint,2,opt,name=Empty,proto3" json:"Empty,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -88,7 +87,7 @@ func (m *ListFilesystemRes) Reset() { *m = ListFilesystemRes{} } func (m *ListFilesystemRes) String() string { return proto.CompactTextString(m) } func (*ListFilesystemRes) ProtoMessage() {} func (*ListFilesystemRes) Descriptor() ([]byte, []int) { - return fileDescriptor_pdu_759e477f62b58e58, []int{1} + return fileDescriptor_pdu_83b7e2a28d820622, []int{1} } func (m *ListFilesystemRes) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_ListFilesystemRes.Unmarshal(m, b) @@ -115,16 +114,10 @@ func (m *ListFilesystemRes) GetFilesystems() []*Filesystem { return nil } -func (m *ListFilesystemRes) GetEmpty() bool { - if m != nil { - return m.Empty - } - return false -} - type Filesystem struct { Path string `protobuf:"bytes,1,opt,name=Path,proto3" json:"Path,omitempty"` ResumeToken string `protobuf:"bytes,2,opt,name=ResumeToken,proto3" json:"ResumeToken,omitempty"` + IsPlaceholder bool `protobuf:"varint,3,opt,name=IsPlaceholder,proto3" json:"IsPlaceholder,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -134,7 +127,7 @@ func (m *Filesystem) Reset() { *m = Filesystem{} } func (m *Filesystem) String() string { return proto.CompactTextString(m) } func (*Filesystem) ProtoMessage() {} func (*Filesystem) Descriptor() ([]byte, []int) { - return fileDescriptor_pdu_759e477f62b58e58, []int{2} + return fileDescriptor_pdu_83b7e2a28d820622, []int{2} } func (m *Filesystem) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Filesystem.Unmarshal(m, b) @@ -168,6 +161,13 @@ func (m *Filesystem) GetResumeToken() string { return "" } +func (m *Filesystem) GetIsPlaceholder() bool { + if m != nil { + return m.IsPlaceholder + } + return false +} + type ListFilesystemVersionsReq struct { Filesystem string `protobuf:"bytes,1,opt,name=Filesystem,proto3" json:"Filesystem,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` @@ -179,7 +179,7 @@ func (m *ListFilesystemVersionsReq) Reset() { *m = ListFilesystemVersion func (m *ListFilesystemVersionsReq) String() string { return proto.CompactTextString(m) } func (*ListFilesystemVersionsReq) ProtoMessage() {} func (*ListFilesystemVersionsReq) Descriptor() ([]byte, []int) { - return fileDescriptor_pdu_759e477f62b58e58, []int{3} + return fileDescriptor_pdu_83b7e2a28d820622, []int{3} } func (m *ListFilesystemVersionsReq) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_ListFilesystemVersionsReq.Unmarshal(m, b) @@ -217,7 +217,7 @@ func (m *ListFilesystemVersionsRes) Reset() { *m = ListFilesystemVersion func (m *ListFilesystemVersionsRes) String() string { return proto.CompactTextString(m) } func (*ListFilesystemVersionsRes) ProtoMessage() {} func (*ListFilesystemVersionsRes) Descriptor() ([]byte, []int) { - return fileDescriptor_pdu_759e477f62b58e58, []int{4} + return fileDescriptor_pdu_83b7e2a28d820622, []int{4} } func (m *ListFilesystemVersionsRes) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_ListFilesystemVersionsRes.Unmarshal(m, b) @@ -259,7 +259,7 @@ func (m *FilesystemVersion) Reset() { *m = FilesystemVersion{} } func (m *FilesystemVersion) String() string { return proto.CompactTextString(m) } func (*FilesystemVersion) ProtoMessage() {} func (*FilesystemVersion) Descriptor() ([]byte, []int) { - return fileDescriptor_pdu_759e477f62b58e58, []int{5} + return fileDescriptor_pdu_83b7e2a28d820622, []int{5} } func (m *FilesystemVersion) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_FilesystemVersion.Unmarshal(m, b) @@ -339,7 +339,7 @@ func (m *SendReq) Reset() { *m = SendReq{} } func (m *SendReq) String() string { return proto.CompactTextString(m) } func (*SendReq) ProtoMessage() {} func (*SendReq) Descriptor() ([]byte, []int) { - return fileDescriptor_pdu_759e477f62b58e58, []int{6} + return fileDescriptor_pdu_83b7e2a28d820622, []int{6} } func (m *SendReq) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_SendReq.Unmarshal(m, b) @@ -420,7 +420,7 @@ func (m *Property) Reset() { *m = Property{} } func (m *Property) String() string { return proto.CompactTextString(m) } func (*Property) ProtoMessage() {} func (*Property) Descriptor() ([]byte, []int) { - return fileDescriptor_pdu_759e477f62b58e58, []int{7} + return fileDescriptor_pdu_83b7e2a28d820622, []int{7} } func (m *Property) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Property.Unmarshal(m, b) @@ -470,7 +470,7 @@ func (m *SendRes) Reset() { *m = SendRes{} } func (m *SendRes) String() string { return proto.CompactTextString(m) } func (*SendRes) ProtoMessage() {} func (*SendRes) Descriptor() ([]byte, []int) { - return fileDescriptor_pdu_759e477f62b58e58, []int{8} + return fileDescriptor_pdu_83b7e2a28d820622, []int{8} } func (m *SendRes) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_SendRes.Unmarshal(m, b) @@ -524,7 +524,7 @@ func (m *ReceiveReq) Reset() { *m = ReceiveReq{} } func (m *ReceiveReq) String() string { return proto.CompactTextString(m) } func (*ReceiveReq) ProtoMessage() {} func (*ReceiveReq) Descriptor() ([]byte, []int) { - return fileDescriptor_pdu_759e477f62b58e58, []int{9} + return fileDescriptor_pdu_83b7e2a28d820622, []int{9} } func (m *ReceiveReq) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_ReceiveReq.Unmarshal(m, b) @@ -568,7 +568,7 @@ func (m *ReceiveRes) Reset() { *m = ReceiveRes{} } func (m *ReceiveRes) String() string { return proto.CompactTextString(m) } func (*ReceiveRes) ProtoMessage() {} func (*ReceiveRes) Descriptor() ([]byte, []int) { - return fileDescriptor_pdu_759e477f62b58e58, []int{10} + return fileDescriptor_pdu_83b7e2a28d820622, []int{10} } func (m *ReceiveRes) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_ReceiveRes.Unmarshal(m, b) @@ -601,7 +601,7 @@ func (m *DestroySnapshotsReq) Reset() { *m = DestroySnapshotsReq{} } func (m *DestroySnapshotsReq) String() string { return proto.CompactTextString(m) } func (*DestroySnapshotsReq) ProtoMessage() {} func (*DestroySnapshotsReq) Descriptor() ([]byte, []int) { - return fileDescriptor_pdu_759e477f62b58e58, []int{11} + return fileDescriptor_pdu_83b7e2a28d820622, []int{11} } func (m *DestroySnapshotsReq) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_DestroySnapshotsReq.Unmarshal(m, b) @@ -647,7 +647,7 @@ func (m *DestroySnapshotRes) Reset() { *m = DestroySnapshotRes{} } func (m *DestroySnapshotRes) String() string { return proto.CompactTextString(m) } func (*DestroySnapshotRes) ProtoMessage() {} func (*DestroySnapshotRes) Descriptor() ([]byte, []int) { - return fileDescriptor_pdu_759e477f62b58e58, []int{12} + return fileDescriptor_pdu_83b7e2a28d820622, []int{12} } func (m *DestroySnapshotRes) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_DestroySnapshotRes.Unmarshal(m, b) @@ -692,7 +692,7 @@ func (m *DestroySnapshotsRes) Reset() { *m = DestroySnapshotsRes{} } func (m *DestroySnapshotsRes) String() string { return proto.CompactTextString(m) } func (*DestroySnapshotsRes) ProtoMessage() {} func (*DestroySnapshotsRes) Descriptor() ([]byte, []int) { - return fileDescriptor_pdu_759e477f62b58e58, []int{13} + return fileDescriptor_pdu_83b7e2a28d820622, []int{13} } func (m *DestroySnapshotsRes) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_DestroySnapshotsRes.Unmarshal(m, b) @@ -734,7 +734,7 @@ func (m *ReplicationCursorReq) Reset() { *m = ReplicationCursorReq{} } func (m *ReplicationCursorReq) String() string { return proto.CompactTextString(m) } func (*ReplicationCursorReq) ProtoMessage() {} func (*ReplicationCursorReq) Descriptor() ([]byte, []int) { - return fileDescriptor_pdu_759e477f62b58e58, []int{14} + return fileDescriptor_pdu_83b7e2a28d820622, []int{14} } func (m *ReplicationCursorReq) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_ReplicationCursorReq.Unmarshal(m, b) @@ -882,7 +882,7 @@ func (m *ReplicationCursorReq_GetOp) Reset() { *m = ReplicationCursorReq func (m *ReplicationCursorReq_GetOp) String() string { return proto.CompactTextString(m) } func (*ReplicationCursorReq_GetOp) ProtoMessage() {} func (*ReplicationCursorReq_GetOp) Descriptor() ([]byte, []int) { - return fileDescriptor_pdu_759e477f62b58e58, []int{14, 0} + return fileDescriptor_pdu_83b7e2a28d820622, []int{14, 0} } func (m *ReplicationCursorReq_GetOp) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_ReplicationCursorReq_GetOp.Unmarshal(m, b) @@ -913,7 +913,7 @@ func (m *ReplicationCursorReq_SetOp) Reset() { *m = ReplicationCursorReq func (m *ReplicationCursorReq_SetOp) String() string { return proto.CompactTextString(m) } func (*ReplicationCursorReq_SetOp) ProtoMessage() {} func (*ReplicationCursorReq_SetOp) Descriptor() ([]byte, []int) { - return fileDescriptor_pdu_759e477f62b58e58, []int{14, 1} + return fileDescriptor_pdu_83b7e2a28d820622, []int{14, 1} } func (m *ReplicationCursorReq_SetOp) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_ReplicationCursorReq_SetOp.Unmarshal(m, b) @@ -954,7 +954,7 @@ func (m *ReplicationCursorRes) Reset() { *m = ReplicationCursorRes{} } func (m *ReplicationCursorRes) String() string { return proto.CompactTextString(m) } func (*ReplicationCursorRes) ProtoMessage() {} func (*ReplicationCursorRes) Descriptor() ([]byte, []int) { - return fileDescriptor_pdu_759e477f62b58e58, []int{15} + return fileDescriptor_pdu_83b7e2a28d820622, []int{15} } func (m *ReplicationCursorRes) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_ReplicationCursorRes.Unmarshal(m, b) @@ -1090,7 +1090,7 @@ func (m *PingReq) Reset() { *m = PingReq{} } func (m *PingReq) String() string { return proto.CompactTextString(m) } func (*PingReq) ProtoMessage() {} func (*PingReq) Descriptor() ([]byte, []int) { - return fileDescriptor_pdu_759e477f62b58e58, []int{16} + return fileDescriptor_pdu_83b7e2a28d820622, []int{16} } func (m *PingReq) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_PingReq.Unmarshal(m, b) @@ -1129,7 +1129,7 @@ func (m *PingRes) Reset() { *m = PingRes{} } func (m *PingRes) String() string { return proto.CompactTextString(m) } func (*PingRes) ProtoMessage() {} func (*PingRes) Descriptor() ([]byte, []int) { - return fileDescriptor_pdu_759e477f62b58e58, []int{17} + return fileDescriptor_pdu_83b7e2a28d820622, []int{17} } func (m *PingRes) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_PingRes.Unmarshal(m, b) @@ -1384,57 +1384,58 @@ var _Replication_serviceDesc = grpc.ServiceDesc{ Metadata: "pdu.proto", } -func init() { proto.RegisterFile("pdu.proto", fileDescriptor_pdu_759e477f62b58e58) } +func init() { proto.RegisterFile("pdu.proto", fileDescriptor_pdu_83b7e2a28d820622) } -var fileDescriptor_pdu_759e477f62b58e58 = []byte{ - // 779 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x55, 0x51, 0x8f, 0xe2, 0x36, - 0x10, 0xde, 0x40, 0x80, 0x30, 0xac, 0xee, 0x58, 0x2f, 0x3d, 0xa5, 0x69, 0x7b, 0x42, 0xbe, 0x17, - 0xae, 0x52, 0xd3, 0x8a, 0xf6, 0xa5, 0xaa, 0x54, 0xa9, 0x2c, 0x7b, 0xbb, 0x52, 0xdb, 0x2b, 0x32, - 0xf4, 0xb4, 0xba, 0xb7, 0x14, 0x46, 0x6c, 0xb4, 0x80, 0x73, 0xb6, 0x53, 0x1d, 0x7d, 0xec, 0xbf, - 0xda, 0xff, 0xd0, 0xc7, 0xfe, 0xa0, 0x93, 0x4d, 0x1c, 0xb2, 0x24, 0x48, 0x3c, 0xc5, 0xdf, 0xe7, - 0xcf, 0xe3, 0x99, 0xf1, 0xcc, 0x04, 0xda, 0xc9, 0x22, 0x0d, 0x13, 0xc1, 0x15, 0xa7, 0x97, 0x70, - 0xf1, 0x5b, 0x2c, 0xd5, 0x9b, 0x78, 0x85, 0x72, 0x2b, 0x15, 0xae, 0x19, 0x7e, 0xa0, 0x77, 0x65, - 0x52, 0x92, 0x6f, 0xa0, 0xb3, 0x27, 0xa4, 0xef, 0xf4, 0xeb, 0x83, 0xce, 0xb0, 0x13, 0x16, 0x44, - 0xc5, 0x7d, 0xd2, 0x83, 0xc6, 0xf5, 0x3a, 0x51, 0x5b, 0xbf, 0xd6, 0x77, 0x06, 0x1e, 0xdb, 0x01, - 0x3a, 0x02, 0xd8, 0x8b, 0x08, 0x01, 0x77, 0x12, 0xa9, 0x7b, 0xdf, 0xe9, 0x3b, 0x83, 0x36, 0x33, - 0x6b, 0xd2, 0x87, 0x0e, 0x43, 0x99, 0xae, 0x71, 0xc6, 0x1f, 0x70, 0x63, 0x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84, - 0x47, 0xff, 0x19, 0xc1, 0xf1, 0x3d, 0x49, 0x7e, 0x86, 0xee, 0x61, 0x9d, 0x91, 0x5e, 0x58, 0xd1, - 0x3f, 0x41, 0x15, 0x2b, 0xc9, 0x2f, 0x70, 0x51, 0x7a, 0x12, 0xf2, 0x59, 0xe5, 0xfb, 0x07, 0x95, - 0xb4, 0x1c, 0x35, 0xde, 0xd7, 0x93, 0x45, 0xfa, 0x57, 0xd3, 0xfc, 0xb0, 0xbf, 0xff, 0x14, 0x00, - 0x00, 0xff, 0xff, 0xaf, 0xa9, 0xda, 0x41, 0xbd, 0x07, 0x00, 0x00, +var fileDescriptor_pdu_83b7e2a28d820622 = []byte{ + // 785 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x55, 0xd1, 0x8e, 0xe3, 0x34, + 0x14, 0x9d, 0xb4, 0x69, 0x9b, 0xde, 0x0e, 0xbb, 0x1d, 0x4f, 0x59, 0x85, 0x00, 0xab, 0xca, 0xcb, + 0x43, 0x17, 0x89, 0x80, 0x0a, 0x2f, 0x08, 0x09, 0x89, 0x4e, 0x67, 0x67, 0x10, 0xb0, 0x54, 0x6e, + 0x59, 0xad, 0xf6, 0x2d, 0x34, 0x57, 0x6d, 0x34, 0x6d, 0x9d, 0xb5, 0x13, 0xb4, 0xe5, 0x91, 0xbf, + 0x9a, 0x7f, 0xe0, 0x91, 0x0f, 0x42, 0x76, 0xe3, 0x34, 0x6d, 0x52, 0xa9, 0x4f, 0xf1, 0x39, 0xf7, + 0xda, 0x3e, 0xf7, 0xd8, 0xd7, 0x81, 0x76, 0x1c, 0xa6, 0x7e, 0x2c, 0x78, 0xc2, 0xe9, 0x35, 0x5c, + 0xfd, 0x1a, 0xc9, 0xe4, 0x55, 0xb4, 0x42, 0xb9, 0x95, 0x09, 0xae, 0x19, 0xbe, 0xa7, 0xa3, 0x32, + 0x29, 0xc9, 0x57, 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0x6c, 0x71, 0xa1, 0xf5, 0x1b, 0x4a, 0x19, 0x2c, 0x4c, 0x53, 0x19, 0x48, + 0x3f, 0x37, 0x49, 0x52, 0xb5, 0xdd, 0xed, 0x7c, 0xc9, 0x4d, 0xdb, 0xa9, 0xf1, 0xf0, 0xb1, 0xa6, + 0xde, 0x80, 0x5c, 0x1a, 0xf1, 0xc0, 0x56, 0xe9, 0xc4, 0xf1, 0xb3, 0xa5, 0x3d, 0x33, 0x92, 0xe4, + 0x7b, 0x78, 0x7a, 0xf8, 0x44, 0x4b, 0x42, 0xfc, 0xd2, 0x4f, 0xcb, 0x2b, 0x73, 0x92, 0x4c, 0xe0, + 0x59, 0xf5, 0xeb, 0x4e, 0x3c, 0xff, 0xe4, 0x3f, 0xc3, 0x3b, 0x1d, 0x93, 0xe4, 0x47, 0xe8, 0x1e, + 0xdf, 0x33, 0xd2, 0xf3, 0x2b, 0xfa, 0xc7, 0xab, 0x62, 0x25, 0xf9, 0x09, 0xae, 0x4a, 0x47, 0x42, + 0x3e, 0xae, 0x3c, 0x7f, 0xaf, 0x92, 0x96, 0xa3, 0xc6, 0xbb, 0x7a, 0x1c, 0xa6, 0x7f, 0x36, 0xf5, + 0x0f, 0xfc, 0xdb, 0xff, 0x03, 0x00, 0x00, 0xff, 0xff, 0x37, 0x0e, 0xf2, 0xe4, 0xcd, 0x07, 0x00, + 0x00, } diff --git a/replication/logic/pdu/pdu.proto b/replication/logic/pdu/pdu.proto index 15be58e..2097af5 100644 --- a/replication/logic/pdu/pdu.proto +++ b/replication/logic/pdu/pdu.proto @@ -14,12 +14,12 @@ message ListFilesystemReq {} message ListFilesystemRes { repeated Filesystem Filesystems = 1; - bool Empty = 2; } message Filesystem { string Path = 1; string ResumeToken = 2; + bool IsPlaceholder = 3; } message ListFilesystemVersionsReq { diff --git a/replication/logic/replication_logic.go b/replication/logic/replication_logic.go index cf29596..906b610 100644 --- a/replication/logic/replication_logic.go +++ b/replication/logic/replication_logic.go @@ -108,7 +108,7 @@ type Filesystem struct { receiver Receiver Path string // compat - receiverFSExists bool // compat + receiverFS *pdu.Filesystem promBytesReplicated prometheus.Counter // compat } @@ -237,10 +237,10 @@ func (p *Planner) doPlanning(ctx context.Context) ([]*Filesystem, error) { q := make([]*Filesystem, 0, len(sfss)) for _, fs := range sfss { - receiverFSExists := false + var receiverFS *pdu.Filesystem for _, rfs := range rfss { if rfs.Path == fs.Path { - receiverFSExists = true + receiverFS = rfs } } @@ -250,7 +250,7 @@ func (p *Planner) doPlanning(ctx context.Context) ([]*Filesystem, error) { sender: p.sender, receiver: p.receiver, Path: fs.Path, - receiverFSExists: receiverFSExists, + receiverFS: receiverFS, promBytesReplicated: ctr, }) } @@ -278,7 +278,7 @@ func (fs *Filesystem) doPlanning(ctx context.Context) ([]*Step, error) { } var rfsvs []*pdu.FilesystemVersion - if fs.receiverFSExists { + if fs.receiverFS != nil && !fs.receiverFS.GetIsPlaceholder() { rfsvsres, err := fs.receiver.ListFilesystemVersions(ctx, &pdu.ListFilesystemVersionsReq{Filesystem: fs.Path}) if err != nil { log.WithError(err).Error("receiver error") @@ -301,7 +301,7 @@ func (fs *Filesystem) doPlanning(ctx context.Context) ([]*Step, error) { log.WithField("problem", msg).Error("cannot resolve conflict") } } - if path == nil { + if len(path) == 0 { return nil, conflict } diff --git a/zfs/placeholder.go b/zfs/placeholder.go index 5fb1729..50ddd7f 100644 --- a/zfs/placeholder.go +++ b/zfs/placeholder.go @@ -105,3 +105,9 @@ func ZFSCreatePlaceholderFilesystem(p *DatasetPath) (err error) { return } + +func ZFSSetNoPlaceholder(p *DatasetPath) error { + props := NewZFSProperties() + props.Set(ZREPL_PLACEHOLDER_PROPERTY_NAME, "off") + return zfsSet(p.ToString(), props) +} \ No newline at end of file diff --git a/zfs/zfs.go b/zfs/zfs.go index 8f08a66..652a494 100644 --- a/zfs/zfs.go +++ b/zfs/zfs.go @@ -9,6 +9,7 @@ import ( "io" "os" "os/exec" + "sort" "strings" "sync" "time" @@ -691,17 +692,62 @@ type StreamCopier interface { Close() error } +type RecvOptions struct { + // Rollback to the oldest snapshot, destroy it, then perform `recv -F`. + // Note that this doesn't change property values, i.e. an existing local property value will be kept. + RollbackAndForceRecv bool +} -func ZFSRecv(ctx context.Context, fs string, streamCopier StreamCopier, additionalArgs ...string) (err error) { +func ZFSRecv(ctx context.Context, fs string, streamCopier StreamCopier, opts RecvOptions) (err error) { if err := validateZFSFilesystem(fs); err != nil { return err } + fsdp, err := NewDatasetPath(fs) + if err != nil { + return err + } + + if opts.RollbackAndForceRecv { + // destroy all snapshots before `recv -F` because `recv -F` + // does not perform a rollback unless `send -R` was used (which we assume hasn't been the case) + var snaps []FilesystemVersion + { + vs, err := ZFSListFilesystemVersions(fsdp, nil) + if err != nil { + err = fmt.Errorf("cannot list versions to rollback is required: %s", err) + } + for _, v := range vs { + if v.Type == Snapshot { + snaps = append(snaps, v) + } + } + sort.Slice(snaps, func(i, j int) bool { + return snaps[i].CreateTXG < snaps[j].CreateTXG + }) + } + // bookmarks are rolled back automatically + if len(snaps) > 0 { + // use rollback to efficiently destroy all but the earliest snapshot + // then destroy that earliest snapshot + // afterwards, `recv -F` will work + rollbackTarget := snaps[0] + rollbackTargetAbs := rollbackTarget.ToAbsPath(fsdp) + debug("recv: rollback to %q", rollbackTargetAbs) + if err := ZFSRollback(fsdp, rollbackTarget, "-r"); err != nil { + return fmt.Errorf("cannot rollback %s to %s for forced receive: %s", fsdp.ToString(), rollbackTarget, err) + } + debug("recv: destroy %q", rollbackTargetAbs) + if err := ZFSDestroy(rollbackTargetAbs); err != nil { + return fmt.Errorf("cannot destroy %s for forced receive: %s", rollbackTargetAbs, err) + } + } + } args := make([]string, 0) args = append(args, "recv") - if len(args) > 0 { - args = append(args, additionalArgs...) + if opts.RollbackAndForceRecv { + args = append(args, "-F") } args = append(args, fs) @@ -1038,3 +1084,33 @@ func ZFSBookmark(fs *DatasetPath, snapshot, bookmark string) (err error) { return } + +func ZFSRollback(fs *DatasetPath, snapshot FilesystemVersion, rollbackArgs ...string) (err error) { + + snapabs := snapshot.ToAbsPath(fs) + if snapshot.Type != Snapshot { + return fmt.Errorf("can only rollback to snapshots, got %s", snapabs) + } + + args := []string{"rollback"} + args = append(args, rollbackArgs...) + args = append(args, snapabs) + + cmd := exec.Command(ZFS_BINARY, args...) + + stderr := bytes.NewBuffer(make([]byte, 0, 1024)) + cmd.Stderr = stderr + + if err = cmd.Start(); err != nil { + return err + } + + if err = cmd.Wait(); err != nil { + err = &ZFSError{ + Stderr: stderr.Bytes(), + WaitErr: err, + } + } + + return err +}