fix: report correct DatabaseStateCode (#2543)

* fix: report correct DatabaseStateCode

* chore: fix lint

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
pull/24376/head
Raphael Taylor-Davies 2021-09-15 19:02:54 +01:00 committed by GitHub
parent 6f2301e16c
commit 1ea4335ff3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 53 additions and 98 deletions

View File

@ -1,49 +0,0 @@
/// Simple representation of the state a database can be in.
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum DatabaseStateCode {
/// Database is known but nothing is loaded.
Known,
/// Database object storage has been found
DatabaseObjectStoreFound,
/// Rules are loaded
RulesLoaded,
/// Catalog is loaded but data from sequencers / write buffers is not yet replayed.
CatalogLoaded,
/// Error loading rules
RulesLoadError,
/// Error loading catalog
CatalogLoadError,
/// Error during replay
ReplayError,
/// Fully initialized database.
Initialized,
}
impl DatabaseStateCode {
/// Returns a human readable description
pub fn description(&self) -> &'static str {
match self {
DatabaseStateCode::Known => "Known",
DatabaseStateCode::DatabaseObjectStoreFound => "DatabaseObjectStoreFound",
DatabaseStateCode::RulesLoaded => "RulesLoaded",
DatabaseStateCode::CatalogLoaded => "CatalogLoaded",
DatabaseStateCode::RulesLoadError => "RulesLoadError",
DatabaseStateCode::CatalogLoadError => "CatalogLoadError",
DatabaseStateCode::ReplayError => "ReplayError",
DatabaseStateCode::Initialized => "Initialized",
}
}
}
impl std::fmt::Display for DatabaseStateCode {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.description().fmt(f)
}
}

View File

@ -14,7 +14,6 @@ pub mod chunk_metadata;
pub mod consistent_hasher;
mod database_name;
pub mod database_rules;
pub mod database_state;
pub mod deleted_database;
pub mod error;
pub mod instant;

View File

@ -37,8 +37,8 @@ service ManagementService {
rpc DeleteDatabase(DeleteDatabaseRequest) returns (DeleteDatabaseResponse);
// List deleted databases and their metadata.
rpc ListDeletedDatabases(ListDeletedDatabasesRequest) returns (ListDeletedDatabasesResponse);
// List deleted databases and their metadata.
rpc ListDeletedDatabases(ListDeletedDatabasesRequest) returns (ListDeletedDatabasesResponse);
// List chunks available on this database
rpc ListChunks(ListChunksRequest) returns (ListChunksResponse);
@ -177,16 +177,16 @@ message DeleteDatabaseResponse {}
message ListDeletedDatabasesRequest {}
message ListDeletedDatabasesResponse {
repeated DeletedDatabase deleted_databases = 1;
repeated DeletedDatabase deleted_databases = 1;
}
// This resource represents a deleted database.
message DeletedDatabase {
// The generation ID of the deleted database.
// The generation ID of the deleted database.
uint64 generation_id = 1;
// The UTC datetime at which this database was deleted.
google.protobuf.Timestamp deleted_at = 2;
// The UTC datetime at which this database was deleted.
google.protobuf.Timestamp deleted_at = 2;
// The name of the deleted database.
string db_name = 3;
@ -366,8 +366,11 @@ message DatabaseStatus {
// Database is known but nothing is loaded.
DATABASE_STATE_KNOWN = 1;
// Database object storage has been found
DATABASE_STATE_DATABASE_OBJECT_STORE_FOUND = 8;
// Database object storage has been found
DATABASE_STATE_DATABASE_OBJECT_STORE_FOUND = 8;
// No active database
DATABASE_STATE_NO_ACTIVE_DATABASE = 10;
// Rules are loaded
DATABASE_STATE_RULES_LOADED = 2;
@ -386,6 +389,9 @@ message DatabaseStatus {
// Error during replay
DATABASE_STATE_REPLAY_ERROR = 7;
// Error encountered identifying active generation
DATABASE_STATE_DATABASE_OBJECT_STORE_LOOKUP_ERROR = 9;
}
// Current initialization state of the database.
@ -463,7 +469,7 @@ message DeleteRequest {
// predicate
// conjunctive expressions of binary 'column_name = literal' or 'column_ame != literal'
string predicate = 5;
string predicate = 5;
}
message DeleteResponse {

View File

@ -1,26 +1,27 @@
use crate::influxdata::iox::management::v1 as management;
use data_types::database_state::DatabaseStateCode;
pub use crate::influxdata::iox::management::v1::database_status::DatabaseState;
use std::fmt::Formatter;
impl From<DatabaseStateCode> for management::database_status::DatabaseState {
fn from(state_code: DatabaseStateCode) -> Self {
match state_code {
DatabaseStateCode::Known => Self::Known,
DatabaseStateCode::DatabaseObjectStoreFound => Self::DatabaseObjectStoreFound,
DatabaseStateCode::RulesLoaded => Self::RulesLoaded,
DatabaseStateCode::CatalogLoaded => Self::CatalogLoaded,
DatabaseStateCode::Initialized => Self::Initialized,
DatabaseStateCode::RulesLoadError => Self::RulesLoadError,
DatabaseStateCode::CatalogLoadError => Self::CatalogLoadError,
DatabaseStateCode::ReplayError => Self::ReplayError,
impl DatabaseState {
/// Returns a human readable description
pub fn description(&self) -> &'static str {
match self {
DatabaseState::Known => "Known",
DatabaseState::RulesLoaded => "RulesLoaded",
DatabaseState::CatalogLoaded => "CatalogLoaded",
DatabaseState::RulesLoadError => "RulesLoadError",
DatabaseState::CatalogLoadError => "CatalogLoadError",
DatabaseState::ReplayError => "ReplayError",
DatabaseState::Initialized => "Initialized",
DatabaseState::DatabaseObjectStoreFound => "DatabaseObjectStoreFound",
DatabaseState::DatabaseObjectStoreLookupError => "DatabaseObjectStoreLookupError",
DatabaseState::NoActiveDatabase => "NoActiveDatabase",
DatabaseState::Unspecified => "Unspecified",
}
}
}
impl From<Option<DatabaseStateCode>> for management::database_status::DatabaseState {
fn from(state_code: Option<DatabaseStateCode>) -> Self {
match state_code {
Some(state_code) => state_code.into(),
None => Self::Unspecified,
}
impl std::fmt::Display for DatabaseState {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.write_str(self.description())
}
}

View File

@ -7,12 +7,12 @@ use crate::{
rules::ProvidedDatabaseRules,
ApplicationState, Db,
};
use data_types::database_rules::WriteBufferDirection;
use data_types::{database_state::DatabaseStateCode, server_id::ServerId, DatabaseName};
use data_types::{database_rules::WriteBufferDirection, server_id::ServerId, DatabaseName};
use futures::{
future::{BoxFuture, FusedFuture, Shared},
FutureExt, TryFutureExt,
};
use generated_types::database_state::DatabaseState as DatabaseStateCode;
use internal_types::freezable::Freezable;
use iox_object_store::IoxObjectStore;
use observability_deps::tracing::{error, info, warn};
@ -809,11 +809,13 @@ impl DatabaseState {
DatabaseState::RulesLoaded(_) => DatabaseStateCode::RulesLoaded,
DatabaseState::CatalogLoaded(_) => DatabaseStateCode::CatalogLoaded,
DatabaseState::Initialized(_) => DatabaseStateCode::Initialized,
DatabaseState::DatabaseObjectStoreLookupError(_, _) => DatabaseStateCode::Known,
DatabaseState::NoActiveDatabase(_, _) => DatabaseStateCode::Known,
DatabaseState::RulesLoadError(_, _) => DatabaseStateCode::DatabaseObjectStoreFound,
DatabaseState::CatalogLoadError(_, _) => DatabaseStateCode::RulesLoaded,
DatabaseState::ReplayError(_, _) => DatabaseStateCode::CatalogLoaded,
DatabaseState::DatabaseObjectStoreLookupError(_, _) => {
DatabaseStateCode::DatabaseObjectStoreLookupError
}
DatabaseState::NoActiveDatabase(_, _) => DatabaseStateCode::NoActiveDatabase,
DatabaseState::RulesLoadError(_, _) => DatabaseStateCode::RulesLoadError,
DatabaseState::CatalogLoadError(_, _) => DatabaseStateCode::CatalogLoadError,
DatabaseState::ReplayError(_, _) => DatabaseStateCode::ReplayError,
}
}
@ -1216,7 +1218,7 @@ mod tests {
let (application, database) = initialized_database().await;
database.delete().await.unwrap();
assert_eq!(database.state_code(), DatabaseStateCode::Known);
assert_eq!(database.state_code(), DatabaseStateCode::NoActiveDatabase);
assert!(matches!(
database.init_error().unwrap().as_ref(),
InitError::NoActiveDatabase

View File

@ -2298,7 +2298,7 @@ mod tests {
.unwrap_err()
.to_string(),
"error wiping preserved catalog: database (db_broken_rules) in invalid state \
(DatabaseObjectStoreFound) for transition (WipePreservedCatalog)"
(RulesLoadError) for transition (WipePreservedCatalog)"
);
// 4. wipe DB with broken catalog, this will bring the DB back to life

View File

@ -446,16 +446,12 @@ where
.map(|databases| {
databases
.into_iter()
.map(|database| {
let state: database_status::DatabaseState = database.state_code().into();
DatabaseStatus {
db_name: database.config().name.to_string(),
error: database.init_error().map(|e| ProtobufError {
message: e.to_string(),
}),
state: state.into(),
}
.map(|database| DatabaseStatus {
db_name: database.config().name.to_string(),
error: database.init_error().map(|e| ProtobufError {
message: e.to_string(),
}),
state: database.state_code().into(),
})
.collect()
})

View File

@ -1215,7 +1215,7 @@ async fn test_get_server_status_db_error() {
.contains("error deserializing database rules"));
assert_eq!(
DatabaseState::from_i32(db_status.state).unwrap(),
DatabaseState::DatabaseObjectStoreFound
DatabaseState::RulesLoadError
);
}