Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfixes, bump to 1.1.0 #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "sensorlog"
description = "A lightweight data logging service"
repository = "https://github.com/nyantec.sensorlog"
version = "1.0.0"
version = "1.1.0"
authors = ["The sensorlog Authors <[email protected]>"]
license = "MirOS"

Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl Sensorlog {
Ok(measurements)
}

pub fn set_storage_quota_for(&mut self, sensor_id: &str, quota: ::quota::StorageQuota) {
pub fn set_storage_quota_for(&mut self, sensor_id: &str, quota: ::quota::StorageQuota) -> Result<(), Error> {
let logfile_id = LogfileID::from_string(sensor_id.to_string());
self.logfile_map.set_storage_quota_for(&logfile_id, quota)
}
Expand Down
24 changes: 22 additions & 2 deletions src/logfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,13 @@ impl Logfile {
storage_locked.allocate(measurement_size)?;

// insert the new measurement into the head partition
match storage_locked.partitions.last_mut() {
Some(p) => p.append_measurement(measurement)?,
match &mut storage_locked.partitions.last_mut() {
Some(p) => {
p.append_measurement(measurement)?;
let part_name = p.get_file_name();
// Make sure that the currently used partition is not in self.deleted_partition
storage_locked.partitions_deleted.retain(|x| x.get_file_name() != part_name);
},
None => return Err(err_server!("corrupt partition map")),
};

Expand All @@ -173,6 +178,21 @@ impl Logfile {
let reader = LogfileReader::new(&storage_locked.partitions);
reader.fetch_measurements(time_start, time_limit, limit)
}

pub fn set_storage_quota(&self, quota: StorageQuota) -> Result<(), ::Error> {
if quota.is_zero() {
return Err(err_quota!("insufficient quota"));
}

// lock the storage
let mut storage_locked = match self.storage.write() {
Ok(l) => l,
Err(_) => fatal!("lock is poisoned"),
};
storage_locked.storage_quota = quota;

Ok(())
}
}

impl LogfileStorage {
Expand Down
14 changes: 9 additions & 5 deletions src/logfile_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,17 @@ impl LogfileMap {
Ok(logfile)
}

pub fn set_storage_quota_for(&mut self, logfile_id: &LogfileID, quota: ::quota::StorageQuota) {
self.config.set_storage_quota_for(&logfile_id, quota);
// grab write lock
let mut logfiles_locked = match self.logfiles.write() {
pub fn set_storage_quota_for(&mut self, logfile_id: &LogfileID, quota: ::quota::StorageQuota) -> Result<(), ::Error> {
self.config.set_storage_quota_for(&logfile_id, quota.clone());

let logfiles_locked = match self.logfiles.read() {
Ok(l) => l,
Err(_) => fatal!("lock is poisoned"),
};
logfiles_locked.remove(&logfile_id.get_string());
if let Some(logfile) = logfiles_locked.get(&logfile_id.get_string()) {
logfile.set_storage_quota(quota)?;
}

Ok(())
}
}
2 changes: 1 addition & 1 deletion src/quota.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* of said person’s immediate fault when using the work as intended.
*/

#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub enum StorageQuota {
Unlimited,
Limited { limit_bytes: u64 },
Expand Down