common_meta/ddl/allocator/
resource_id.rs

1// Copyright 2023 Greptime Team
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use std::ops::Range;
16use std::sync::Arc;
17
18use crate::error::Result;
19
20pub type ResourceIdAllocatorRef = Arc<dyn ResourceIdAllocator>;
21
22#[async_trait::async_trait]
23pub trait ResourceIdAllocator: Send + Sync {
24    /// Returns the next value and increments the sequence.
25    async fn next(&self) -> Result<u64>;
26
27    /// Returns the current value stored in the remote storage without incrementing the sequence.
28    async fn peek(&self) -> Result<u64>;
29
30    /// Jumps to the given value.
31    async fn jump_to(&self, next: u64) -> Result<()>;
32
33    /// Returns the range of available sequences.
34    async fn min_max(&self) -> Range<u64>;
35}