Skip to content

Commit

Permalink
workaround: supply default node info
Browse files Browse the repository at this point in the history
This commit fixes the symptom of a serialization issue, allegedly after
an upgrade from 2.0.5.
My hypothesis is that the problem is introduced due to the upgrade of
the rust compiler. As this could change the way the node-info structure is serialized.

Please note that the storage files of are not forward compatible. So
switching back from newer versions can also introduce problems.
  • Loading branch information
svenrademakers committed Aug 20, 2024
1 parent 2851118 commit f8c86b7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 31 deletions.
14 changes: 12 additions & 2 deletions src/app/bmc_application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use std::time::Duration;
use tokio::fs::OpenOptions;
use tokio::io::{AsyncRead, AsyncSeek, AsyncSeekExt, AsyncWrite, AsyncWriteExt};
use tokio::time::sleep;
use tracing::{debug, info, trace};
use tracing::{debug, info, instrument, trace};

use super::cooling_device::{get_cooling_state, set_cooling_state, CoolingDevice};

Expand Down Expand Up @@ -150,13 +150,16 @@ impl BmcApplication {
self.initialize_cooling().await
}

#[instrument(skip(self), fields(alternative_port, config))]
async fn initialize_usb_mode(&self) -> anyhow::Result<()> {
if self.pin_controller.usb_bus_type() == UsbArchitecture::UsbHub {
let alternative_port = self.app_db.get::<bool>(NODE1_USB_MODE).await;
self.pin_controller.set_node1_usb_route(alternative_port)?;
tracing::Span::current().record("alternative_port", alternative_port);
}

let config = self.app_db.get::<UsbConfig>(USB_CONFIG).await;
tracing::Span::current().record("config", format!("{:?}", config));
self.configure_usb(config).await.context("USB configure")
}

Expand Down Expand Up @@ -238,8 +241,13 @@ impl BmcApplication {
.await
}

#[instrument(skip(self))]
async fn update_power_on_times(&self, activated_nodes: u8, node_states: u8, mask: u8) {
let mut node_infos = self.app_db.get::<NodeInfos>(NODE_INFO_KEY).await;
let mut node_infos = self
.app_db
.try_get::<NodeInfos>(NODE_INFO_KEY)
.await
.unwrap_or_default();

for (idx, new_state) in bit_iterator(node_states, mask) {
let current_state = activated_nodes & (1 << idx);
Expand Down Expand Up @@ -394,6 +402,7 @@ impl BmcApplication {
Ok(())
}

#[instrument(skip(self))]
pub async fn set_node_info(&self, new_info: HashMap<NodeId, NodeInfo>) -> anyhow::Result<()> {
let mut stored_nodes = self.app_db.get::<NodeInfos>(NODE_INFO_KEY).await;

Expand All @@ -420,6 +429,7 @@ impl BmcApplication {
Ok(())
}

#[instrument(skip(self))]
pub async fn get_node_infos(&self) -> anyhow::Result<NodeInfos> {
let Some(current_time) = utils::get_timestamp_unix() else {
anyhow::bail!("Current time before Unix epoch");
Expand Down
38 changes: 9 additions & 29 deletions src/persistency/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,20 @@
// 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.
use std::{borrow::Cow, error::Error, fmt::Display};
use std::borrow::Cow;
use thiserror::Error;

#[derive(Debug)]
#[derive(Debug, Error)]
pub enum PersistencyError<'a> {
#[error("not a {} persistency file", env!("CARGO_PKG_NAME"))]
UnknownFormat,
#[error("version {0} not supported")]
UnsupportedVersion(u32),
#[error("key: {0}, {1}")]
SerializationError(Cow<'a, str>, bincode::Error),
IoError(std::io::Error),
#[error("IO Err:")]
IoError(#[from] std::io::Error),
#[error("{0} is not registered in persistency storage")]
UnknownKey(String),
}

Expand All @@ -30,29 +36,3 @@ impl<'a> PersistencyError<'a> {
PersistencyError::SerializationError(context.into(), error)
}
}

impl<'a> Error for PersistencyError<'a> {}

impl<'a> Display for PersistencyError<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
PersistencyError::UnknownFormat => {
write!(f, "not a {} persistency file", env!("CARGO_PKG_NAME"))
}
PersistencyError::UnsupportedVersion(version) => {
write!(f, "version {} not supported", version)
}
PersistencyError::SerializationError(key, e) => write!(f, "key: {}, {}", key, e),
PersistencyError::IoError(e) => f.write_str(&e.to_string()),
PersistencyError::UnknownKey(key) => {
write!(f, "{} is not registered in persistency storage", key)
}
}
}
}

impl<'a> From<std::io::Error> for PersistencyError<'a> {
fn from(value: std::io::Error) -> Self {
Self::IoError(value)
}
}

0 comments on commit f8c86b7

Please sign in to comment.