diff --git a/protocol.rs b/protocol.rs deleted file mode 100755 index 86aa2cd..0000000 --- a/protocol.rs +++ /dev/null @@ -1,154 +0,0 @@ -// src/common/protocol.rs -//! Протокол обмена данными для Falcot -//! -//! Определяет структуры команд и ответов для взаимодействия между -//! компонентами системы с использованием wait-free сериализации. - -#![allow(dead_code)] - -use serde::{Deserialize, Serialize}; -use crate::server::database::Index; - -/// Команды для выполнения в базе данных -#[derive(Debug, Clone, Serialize, Deserialize)] -pub enum Command { - Create { - collection: String, - document: Vec, - }, - Read { - collection: String, - id: String, - }, - Update { - collection: String, - id: String, - document: Vec, - }, - Delete { - collection: String, - id: String, - }, - Query { - collection: String, - filter: Vec, - }, - CreateProcedure { - name: String, - code: Vec, - }, - CallProcedure { - name: String, - }, - BeginTransaction { - transaction_id: String, - }, - CommitTransaction { - transaction_id: String, - }, - RollbackTransaction { - transaction_id: String, - }, - CreateIndex { - collection: String, - index: Index, - }, - QueryByIndex { - collection: String, - index_name: String, - value: Vec, - }, - // Новые команды для шардинга - AddShardNode { - node_id: String, - address: String, - capacity: u64, - }, - RemoveShardNode { - node_id: String, - }, - MigrateShard { - collection: String, - from_node: String, - to_node: String, - shard_key: String, - }, - RebalanceCluster, - GetClusterStatus, - // Команды для constraints - AddConstraint { - collection: String, - constraint_name: String, - constraint_type: String, - field: String, - value: Vec, - }, - RemoveConstraint { - collection: String, - constraint_name: String, - }, - // Команды для компрессии - EnableCompression { - collection: String, - algorithm: String, - }, - DisableCompression { - collection: String, - }, - // Команды для глобальных индексов - CreateGlobalIndex { - name: String, - field: String, - unique: bool, - }, - QueryGlobalIndex { - index_name: String, - value: Vec, - }, -} - -/// Ответы от базы данных -#[derive(Debug, Clone, Serialize, Deserialize)] -pub enum Response { - Success(Vec), - Error(String), -} - -/// Сообщение для репликации -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct ReplicationMessage { - pub sequence: u64, - pub command: Command, - pub timestamp: i64, -} - -/// Структура для информации о шарде -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct ShardInfo { - pub node_id: String, - pub address: String, - pub capacity: u64, - pub used: u64, - pub collections: Vec, -} - -/// Структура для статуса кластера -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct ClusterStatus { - pub nodes: Vec, - pub total_capacity: u64, - pub total_used: u64, - pub rebalance_needed: bool, -} - -/// Wait-Free сериализация сообщений -pub fn serialize(value: &T) -> crate::common::error::Result> { - rmp_serde::to_vec(value) - .map_err(|e| crate::common::error::FalcotError::SerializationError(e.to_string())) -} - -/// Wait-Free десериализация сообщений -pub fn deserialize<'a, T: serde::Deserialize<'a>>(bytes: &'a [u8]) -> crate::common::error::Result { - rmp_serde::from_slice(bytes) - .map_err(|e| crate::common::error::FalcotError::SerializationError(e.to_string())) -}