github.com/polarismesh/polaris@v1.17.8/store/api.go (about)

     1  /**
     2   * Tencent is pleased to support the open source community by making Polaris available.
     3   *
     4   * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
     5   *
     6   * Licensed under the BSD 3-Clause License (the "License");
     7   * you may not use this file except in compliance with the License.
     8   * You may obtain a copy of the License at
     9   *
    10   * https://opensource.org/licenses/BSD-3-Clause
    11   *
    12   * Unless required by applicable law or agreed to in writing, software distributed
    13   * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
    14   * CONDITIONS OF ANY KIND, either express or implied. See the License for the
    15   * specific language governing permissions and limitations under the License.
    16   */
    17  
    18  package store
    19  
    20  import (
    21  	"time"
    22  
    23  	"github.com/polarismesh/polaris/common/model"
    24  )
    25  
    26  // Store 通用存储接口
    27  type Store interface {
    28  	// Name 存储层的名字
    29  	Name() string
    30  	// Initialize 存储的初始化函数
    31  	Initialize(c *Config) error
    32  	// Destroy 存储的析构函数
    33  	Destroy() error
    34  	// CreateTransaction 创建事务对象
    35  	CreateTransaction() (Transaction, error)
    36  	// StartTx 开启一个原子事务
    37  	StartTx() (Tx, error)
    38  	// StartReadTx 开启一个原子事务
    39  	StartReadTx() (Tx, error)
    40  	// NamespaceStore Service namespace interface
    41  	NamespaceStore
    42  	// NamingModuleStore Service Registration Discovery Module Storage Interface
    43  	NamingModuleStore
    44  	// ConfigFileModuleStore Configure the central module storage interface
    45  	ConfigFileModuleStore
    46  	// ClientStore Client the central module storage interface
    47  	ClientStore
    48  	// AdminStore Maintain inteface
    49  	AdminStore
    50  }
    51  
    52  // NamespaceStore Namespace storage interface
    53  type NamespaceStore interface {
    54  	// AddNamespace Save a namespace
    55  	AddNamespace(namespace *model.Namespace) error
    56  	// UpdateNamespace Update namespace
    57  	UpdateNamespace(namespace *model.Namespace) error
    58  	// UpdateNamespaceToken Update namespace token
    59  	UpdateNamespaceToken(name string, token string) error
    60  	// GetNamespace Get the details of the namespace according to Name
    61  	GetNamespace(name string) (*model.Namespace, error)
    62  	// GetNamespaces Query Namespace from the database
    63  	GetNamespaces(filter map[string][]string, offset, limit int) ([]*model.Namespace, uint32, error)
    64  	// GetMoreNamespaces Get incremental data
    65  	// 此方法用于 cache 增量更新,需要注意 mtime 应为数据库时间戳
    66  	GetMoreNamespaces(mtime time.Time) ([]*model.Namespace, error)
    67  }
    68  
    69  // Transaction Transaction interface, does not support multi-level concurrency operation,
    70  // currently only support a single price serial operation
    71  type Transaction interface {
    72  	// Commit Transaction
    73  	Commit() error
    74  	// LockBootstrap Start the lock, limit the concurrent number of Server boot
    75  	LockBootstrap(key string, server string) error
    76  	// LockNamespace Row it locks Namespace
    77  	LockNamespace(name string) (*model.Namespace, error)
    78  	// DeleteNamespace Delete Namespace
    79  	DeleteNamespace(name string) error
    80  	// LockService Row it locks service
    81  	LockService(name string, namespace string) (*model.Service, error)
    82  	// RLockService Shared lock service
    83  	RLockService(name string, namespace string) (*model.Service, error)
    84  }
    85  
    86  // Tx Atomic matters without any business attributes.Abstraction of different storage type transactions
    87  type Tx interface {
    88  	// Commit Transaction
    89  	Commit() error
    90  	// Rollback transaction
    91  	Rollback() error
    92  	// GetDelegateTx Get the original proxy transaction object.Different storage types have no business implementation
    93  	GetDelegateTx() interface{}
    94  	// CreateReadView create a snapshot read view
    95  	CreateReadView() error
    96  }
    97  
    98  // ToolStore Storage related functions and tool interfaces
    99  type ToolStore interface {
   100  	// GetUnixSecond Get the current time
   101  	GetUnixSecond(maxWait time.Duration) (int64, error)
   102  }