ResourceOperations.h 3.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
// Copyright (C) 2019-2020 Zilliz. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the License
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
// or implied. See the License for the specific language governing permissions and limitations under the License.

#pragma once

#include "db/snapshot/Operations.h"

namespace milvus {
namespace engine {
namespace snapshot {

class CollectionCommitOperation : public CommitOperation<CollectionCommit> {
 public:
    using BaseT = CommitOperation<CollectionCommit>;
    CollectionCommitOperation(OperationContext context, ScopedSnapshotT prev_ss) : BaseT(context, prev_ss) {
    }

    CollectionCommitPtr
    GetPrevResource() const override {
        return prev_ss_->GetCollectionCommit();
    }

31
    Status
32 33 34 35 36 37 38 39 40 41 42
    DoExecute(Store&) override;
};

class PartitionCommitOperation : public CommitOperation<PartitionCommit> {
 public:
    using BaseT = CommitOperation<PartitionCommit>;
    PartitionCommitOperation(const OperationContext& context, ScopedSnapshotT prev_ss);

    PartitionCommitPtr
    GetPrevResource() const override;

43
    Status
44
    DoExecute(Store&) override;
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62

    Status
    PreCheck() override;
};

class PartitionOperation : public CommitOperation<Partition> {
 public:
    using BaseT = CommitOperation<Partition>;
    PartitionOperation(const PartitionContext& context, ScopedSnapshotT prev_ss);

    Status
    DoExecute(Store& store) override;

    Status
    PreCheck() override;

 protected:
    PartitionContext context_;
63 64 65 66 67 68 69 70 71 72
};

class SegmentCommitOperation : public CommitOperation<SegmentCommit> {
 public:
    using BaseT = CommitOperation<SegmentCommit>;
    SegmentCommitOperation(const OperationContext& context, ScopedSnapshotT prev_ss);

    SegmentCommit::Ptr
    GetPrevResource() const override;

73
    Status
74
    DoExecute(Store&) override;
75 76 77

    Status
    PreCheck() override;
78 79 80 81 82 83 84
};

class SegmentOperation : public CommitOperation<Segment> {
 public:
    using BaseT = CommitOperation<Segment>;
    SegmentOperation(const OperationContext& context, ScopedSnapshotT prev_ss);

85
    Status
86
    DoExecute(Store& store) override;
87 88 89

    Status
    PreCheck() override;
90 91 92 93 94 95 96
};

class SegmentFileOperation : public CommitOperation<SegmentFile> {
 public:
    using BaseT = CommitOperation<SegmentFile>;
    SegmentFileOperation(const SegmentFileContext& sc, ScopedSnapshotT prev_ss);

97
    Status
98 99 100 101 102 103 104 105 106 107
    DoExecute(Store& store) override;

 protected:
    SegmentFileContext context_;
};

template <>
class LoadOperation<Collection> : public Operations {
 public:
    explicit LoadOperation(const LoadOperationContext& context)
X
XuPeng-SH 已提交
108
        : Operations(OperationContext(), ScopedSnapshotT(), OperationsType::O_Leaf), context_(context) {
109 110
    }

X
XuPeng-SH 已提交
111
    const Status&
112
    ApplyToStore(Store& store) override {
113
        if (done_) {
114
            Done(store);
115 116 117
            return status_;
        }
        Status status;
118
        if (context_.id == 0 && context_.name != "") {
119
            status = store.GetCollection(context_.name, resource_);
120
        } else {
121
            status = store.GetResource<Collection>(context_.id, resource_);
122
        }
123
        SetStatus(status);
124
        Done(store);
125
        return status_;
126 127
    }

128 129 130 131 132
    Status
    GetResource(CollectionPtr& res, bool wait = true) {
        if (wait) {
            WaitToFinish();
        }
C
Cai Yudong 已提交
133
        STATUS_CHECK(CheckDone());
134 135 136 137
        if (!resource_) {
            return Status(SS_NOT_FOUND_ERROR, "No specified resource");
        }
        res = resource_;
C
Cai Yudong 已提交
138
        return Status::OK();
139 140 141 142 143 144 145 146 147 148
    }

 protected:
    LoadOperationContext context_;
    CollectionPtr resource_;
};

}  // namespace snapshot
}  // namespace engine
}  // namespace milvus