Skip to content

Commit

Permalink
add the function of restoring from metadata been backuped (fluid-clou…
Browse files Browse the repository at this point in the history
…dnative#564)

* add the function of restoring from metadata been backuped

* code improve

Co-authored-by: 仇伶玮 <[email protected]>
  • Loading branch information
yangyuliufeng and 仇伶玮 authored Feb 9, 2021
1 parent a56e352 commit 90cdc4c
Show file tree
Hide file tree
Showing 13 changed files with 357 additions and 53 deletions.
14 changes: 14 additions & 0 deletions api/v1alpha1/dataset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@ type Mount struct {
EncryptOptions []EncryptOption `json:"encryptOptions,omitempty"`
}

// DataRestoreLocation describes the spec restore location of Dataset
type DataRestoreLocation struct {
// Path describes the path of restore, in the form of local://subpath or pvc://<pvcName>/subpath
// +optional
Path string `json:"path,omitempty"`
// NodeName describes the nodeName of restore if Path is in the form of local://subpath
// +optional
NodeName string `json:"nodeName,omitempty"`
}

// DatasetSpec defines the desired state of Dataset
type DatasetSpec struct {
// Mount Points to be mounted on Alluxio.
Expand Down Expand Up @@ -133,6 +143,10 @@ type DatasetSpec struct {
// +kubebuilder:validation:Enum=Exclusive;"";Shared
// +optional
PlacementMode PlacementMode `json:"placement,omitempty"`

// DataRestoreLocation is the location to load data of dataset been backuped
// +optional
DataRestoreLocation *DataRestoreLocation `json:"dataRestoreLocation,omitempty"`
}

// Runtime describes a runtime to be used to support dataset
Expand Down
20 changes: 20 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions charts/alluxio/templates/master/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,15 @@ spec:
name: embedded
{{- end }}
volumeMounts:
{{ if .Values.master.restore.enabled -}}
{{- if .Values.master.restore.pvcName }}
- name: pvc
mountPath: /pvc
{{- else }}
- name: host
mountPath: /host
{{- end }}
{{- end }}
{{- if .Values.master.backupPath }}
- name: backup
mountPath: /alluxio_backups
Expand Down Expand Up @@ -292,6 +301,18 @@ spec:
{{- end }}
restartPolicy: Always
volumes:
{{ if .Values.master.restore.enabled -}}
{{- if .Values.master.restore.pvcName }}
- name: pvc
persistentVolumeClaim:
claimName: {{ .Values.master.restore.pvcName }}
{{- else }}
- name: host
hostPath:
path: {{ .Values.master.restore.path }}
type: DirectoryOrCreate
{{- end }}
{{- end }}
{{- if .Values.master.backupPath }}
- name: backup
hostPath:
Expand Down
8 changes: 7 additions & 1 deletion charts/alluxio/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,13 @@ master:
# JVM options specific to the master container
jvmOptions:
nodeSelector: {}
backupPath:
# backupPath is the path in the host to save metadata and metadata info
backupPath: #<backupPath>
# restore is the location to restore metadata and metadata info from
restore:
enabled: false
# path: /subpath/
# pvcName: pvc-local

jobMaster:
args:
Expand Down
13 changes: 13 additions & 0 deletions charts/fluid/fluid/crds/data.fluid.io_datasets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,19 @@ spec:
items:
type: string
type: array
dataRestoreLocation:
description: DataRestoreLocation is the location to load data of dataset been
backuped
properties:
nodeName:
description: NodeName describes the nodeName of restore if Path
is in the form of local://subpath
type: string
path:
description: Path describes the path of restore, in the form of local://subpath
or pvc://<pvcName>/subpath
type: string
type: object
mounts:
description: Mount Points to be mounted on Alluxio.
items:
Expand Down
13 changes: 13 additions & 0 deletions config/crd/bases/data.fluid.io_datasets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,19 @@ spec:
items:
type: string
type: array
dataRestoreLocation:
description: DataRestoreLocation is the location to load data of dataset been
backuped
properties:
nodeName:
description: NodeName describes the nodeName of restore if Path
is in the form of local://subpath
type: string
path:
description: Path describes the path of restore, in the form of local://subpath
or pvc://<pvcName>/subpath
type: string
type: object
mounts:
description: Mount Points to be mounted on Alluxio.
items:
Expand Down
99 changes: 98 additions & 1 deletion docs/zh/samples/backup_and_restore_metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,101 @@ $ kubectl describe node cn-beijing.192.168.1.146
获得IP地址后,就可以从主机的对应目录取走文件刚刚的两个文件


## 恢复
## 恢复
要进行恢复,需要保证Dataset的名称与原来保持一致,否则会找不到备份文件

### 从PVC恢复
在创建Dataset时,在spec中添加dataRestoreLocation,填入刚刚查询到的路径作为恢复路径

如果备份文件被移动过,需要修改路径
```bash
$ cat <<EOF > dataset.yaml
apiVersion: data.fluid.io/v1alpha1
kind: Dataset
metadata:
name: hbase
spec:
dataRestoreLocation:
path: pvc://pvc-local/subpath1/
mounts:
- mountPoint: https://mirrors.tuna.tsinghua.edu.cn/apache/hbase/2.2.6/
EOF
```

创建Dataset资源对象:
```bash
$ kubectl create -f dataset.yaml
dataset.data.fluid.io/hbase created
```

AlluxioRuntime资源对象无需做特殊配置:
```bash
$ cat<<EOF >runtime.yaml
apiVersion: data.fluid.io/v1alpha1
kind: AlluxioRuntime
metadata:
name: hbase
spec:
replicas: 2
tieredstore:
levels:
- mediumtype: MEM
path: /dev/shm
quota: 2Gi
high: "0.95"
low: "0.7"
properties:
alluxio.user.block.size.bytes.default: 256MB
alluxio.user.streaming.reader.chunk.size.bytes: 256MB
alluxio.user.local.reader.chunk.size.bytes: 256MB
alluxio.worker.network.reader.buffer.size: 256MB
alluxio.user.streaming.data.timeout: 300sec
fuse:
args:
- fuse
- --fuse-opts=kernel_cache,ro,max_read=131072,attr_timeout=7200,entry_timeout=7200,nonempty,max_readahead=0
EOF
```
创建AlluxioRuntime资源对象:
```bash
$ kubectl create -f runtime.yaml
alluxioruntime.data.fluid.io/hbase created
```
数据集加载时,将不再从UFS中加载metadata并统计UFS TOTAL SIZE等信息,而是从备份文件中恢复

片刻后,Dataset进入Bound状态:
```bash
$ kubectl get dataset
NAME UFS TOTAL SIZE CACHED CACHE CAPACITY CACHED PERCENTAGE PHASE AGE
hbase 443.86MiB 0.00B 4.00GiB 0.0% Bound 20h
```
### 从本地恢复
在创建Dataset时,在spec中添加dataRestoreLocation,填入刚刚查询到的路径和备份文件所在主机的nodeName

如果备份文件被移动过,需要修改路径和nodeName
```bash
$ cat <<EOF > dataset.yaml
apiVersion: data.fluid.io/v1alpha1
kind: Dataset
metadata:
name: hbase
spec:
dataRestoreLocation:
path: local:///data/subpath1/
nodeName: cn-beijing.192.168.1.146
mounts:
- mountPoint: https://mirrors.tuna.tsinghua.edu.cn/apache/hbase/2.2.6/
EOF
```
创建AlluxioRuntime资源对象:
```bash
$ kubectl create -f runtime.yaml
alluxioruntime.data.fluid.io/hbase created
```
片刻后,Dataset进入Bound状态
```bash
$ kubectl get dataset
NAME UFS TOTAL SIZE CACHED CACHE CAPACITY CACHED PERCENTAGE PHASE AGE
hbase 443.86MiB 0.00B 4.00GiB 0.0% Bound 20h
```

17 changes: 0 additions & 17 deletions pkg/ddc/alluxio/dataset.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package alluxio

import (
"context"
"github.com/fluid-cloudnative/fluid/pkg/ddc/alluxio/operations"
"reflect"

datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1"
Expand Down Expand Up @@ -127,22 +126,6 @@ func (e *AlluxioEngine) UpdateDatasetStatus(phase datav1alpha1.DatasetPhase) (er
} else {
e.Log.Info("No need to update HCFS status")
}

newFileNum, err := e.getDataSetFileNum()
if err != nil {
return err
} else if newFileNum != datasetToUpdate.Status.FileNum {
datasetToUpdate.Status.FileNum = newFileNum
// backup the filenum result in local
podName, containerName := e.getMasterPodInfo()
fileUtils := operations.NewAlluxioFileUtils(podName, containerName, e.namespace, e.Log)
metadataInfoFile := e.GetMetadataInfoFile()
err = fileUtils.InsertMetaDataInfoIntoFile(operations.FileNum, newFileNum, metadataInfoFile)
if err != nil {
e.Log.Error(err, "Failed to InsertMetaDataInfoIntoFile of the dataset")
}
}

e.Log.Info("the dataset status", "status", datasetToUpdate.Status)

if !reflect.DeepEqual(dataset.Status, datasetToUpdate.Status) {
Expand Down
Loading

0 comments on commit 90cdc4c

Please sign in to comment.