Commit Graph

193 Commits

Author SHA1 Message Date
Matthias Beyer 8b508fe4c3 Optimize backend impl to not hold open files
This patch changes the filesystem-backend implementation of libimagstore
to open files on each read/write rather than holding the file handle in
memory at all times.

Whenever a lot of imag store entries are read into memory, the imag
process may ran out of file descriptors. With this patch applied, a
`Store::get()` call on an entry which is not yet in the store cache
would cause the file to be read, but the FD being dropped after that.
Likewise, a `Store::update()` (which is also called if the imag entry is
dropped) would re-open the file on the filesystem and write the contents
from the imag store cache back to the file.

With this patch, opening hundrets or thousands of imag entries should be
no problem anymore, only the available memory should be a limit then.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-08-11 17:50:22 +02:00
Matthias Beyer aff6ff105d Remove "Header" extension for Value type 2018-07-19 20:58:27 +02:00
Matthias Beyer f6a7345b4a Simplify: Move header verification from Value extension to Entry type 2018-07-19 20:58:27 +02:00
Matthias Beyer 9ad1c8d6bd Simplify: Move default header generation from Value extension to Entry type 2018-07-19 20:58:27 +02:00
Matthias Beyer 1705ecbbff Fix: Remove (empty) Drop implementation for Store
The StoreEntry drop implementation takes care of unlocking the files.
2018-07-19 20:58:27 +02:00
Matthias Beyer b774ac0e67 Fix: Deleting an Entry could leave artifacts in cache
This patch fixes a bug we did not even hit (yet). It is: When deleting
an Entry from the store, this could potentially leave artifacts in the
cache.

Szenario: An Entry, which was loaded (via `Store::get()` for example),
gets `Store::delete()`ed twice. The first call would work as expected,
but leave the Entry in the Store cache. The second call would then fail,
as the Entry is already removed on the FS, but still in the cache. This
would fail - which is the right thing to do here - but with the wrong
error (with a FileError rather than a FileNotFound error).

This patch fixes this.

First of all, the appropriate `PathBuf` object is calculated in all
cases, as this object is needed to check whether the file is actually
there (which could be the case if the Entry is in the cache and if it is
not).

If the entry is in the cache and is borrowed: error. If not, remove the
entry from the cache. Afterwards the file is deleted on disk.

If the entry is not in the cache, but the file exists, the file is removed.
If the file does not exist: error.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-07-19 20:58:27 +02:00
Matthias Beyer 9315a23754 Fix: Use backend abstraction for checking whether a path exists 2018-07-19 20:58:27 +02:00
Matthias Beyer 54c5854761 Remove unnecessary call 2018-06-23 21:56:03 +02:00
Matthias Beyer 3bdd5c959b Add documentation to StoreId type 2018-06-23 21:56:03 +02:00
Matthias Beyer 664edc7943 Update version string: 0.8.0 -> 0.9.0 2018-05-09 11:39:33 +02:00
Matthias Beyer eb20a9d881
Merge pull request #1477 from matthiasbeyer/libimagstore/remove-walk
Remove Store::walk()
2018-05-02 18:39:11 +02:00
Matthias Beyer 258d9f90d3 Remove Store::walk()
This patch removes the Store::walk() interface.

It was cumbersome and unused anyways.
2018-05-02 17:46:45 +02:00
Matthias Beyer 888b31377e Fix: Do not check whether path exists - check whether its a file
This fixes a bug introduced in 195d921218
where we didn't check whether the path is actually a file.
2018-05-02 14:04:59 +02:00
Matthias Beyer 2bf09e7737 Only create directory if it does not exist 2018-05-01 22:29:46 +02:00
Matthias Beyer b27b392f4b Add trace output 2018-05-01 22:29:46 +02:00
Matthias Beyer 972327e35e Remove Store::reset_backend() 2018-05-01 21:09:51 +02:00
Matthias Beyer 2f0a557068 Fix for passing Arc<_> to store interface instead of Box<_> 2018-05-01 21:08:57 +02:00
Matthias Beyer 42e2f18fb3 Pass around Arc<FileAbstraction> internally
Because the iterators need to be able to check whether the file exists
_in the backend_ (not on disk, but in the backend, because of in-memory
test for example), we need to be able to pass the backend to the
iterator intermediate type.

This patch implements this. It does so by changing the internal backend
member of the store from `Box<FileAbstraction>` to
`Arc<FileAbstraction>`, which gives us the ability to clone the
reference to the backend easily without needing to rely on lifetimes
here, because of the Arc.

Also, less boxes are always good.
2018-05-01 21:08:57 +02:00
Matthias Beyer d08c27e623 Rewrite StoreIdIterator extensions
This patch reimplements the iterator extensions.

As we iterate (in StoreIdIterator) over Result<StoreId> now anyways, we
don't need the extensions for Result iterators anymore.

This patch rewrites the extensions to be more simple in every way and
generic over the error type in the iterator.
All the errors have to do is implement From<StoreError>, which is what
they do when linking the generated error types with error_chain to the
libimagstore error types.
2018-05-01 17:44:01 +02:00
Matthias Beyer a2ff298e67 Rewrite Store::entries()
This patch rewrites the Store::entries() function to not be collecting
the iterator.

It therefore introduces a new, internal, iterator type which creates the
StoreId objects from the pathes the PathIterator yields internally.

With this patch, the Store iterator interface changes, as the iterators
now yield `Result<StoreId, StoreError>` instead of `StoreId`.
This is necessary, as the internal conversion errors shouldn't be
hidden.

Of course, the iterator types (like the StoreGetIterator and so on)
should hold a Result<StoreId> internally as well, and also yield
appropritely. This was changed in this commit, too.
2018-05-01 17:44:00 +02:00
Matthias Beyer f4556f3983 Rewrite backend to not collect on pathes_recursively() 2018-05-01 17:44:00 +02:00
Matthias Beyer 900d9f0984
Merge pull request #1474 from matthiasbeyer/libimagstore/cache-flush
Add functionality to flush the internal cache
2018-04-30 21:07:37 +02:00
Matthias Beyer 6a5bcb2709 Remove unused error kinds 2018-04-30 18:54:11 +02:00
Matthias Beyer 6a40ac6b98 Add information about which storeid is the cause of the error in errors 2018-04-30 18:53:54 +02:00
Matthias Beyer 860e47a256 Add functionality to flush the internal cache
Before we had the problem that when iterating over _a lot_ (like 5k)
entries and also fetching them, at some point the OS would return with
"Too many files open".

That is because the store internally caches a lot.

With this change, the Store gets an API to query how big the cache is,
how much the cache can currently hold and (and that's the main thing in
this patch) to flush the cache to disk.

A function to simply ask the store whether its cache should be flushed
(which would us require to ask the OS how many files we can open...
which would be possible with `libc::getrlimit`) does not yet exist,
though, but could be added easily if desired.
2018-04-30 18:39:59 +02:00
Matthias Beyer ea80a5a09b Derive Default for InMemoryFileAbstraction, remove constructor 2018-04-25 19:15:07 +02:00
Matthias Beyer 6a34e7a8fd Derive Default for FSFileAbstraction, reduces boilerplate 2018-04-25 19:15:07 +02:00
Matthias Beyer bf363c4748 Use "if let" if matching on a single pattern 2018-04-25 19:15:07 +02:00
Matthias Beyer f1142c414d Use ok_or_else() instead of ok_or() 2018-04-25 19:15:07 +02:00
Matthias Beyer 22170a0d55 Do not String::from(String) 2018-04-25 19:13:51 +02:00
Matthias Beyer 6f5590713a Use single quotes here 2018-04-25 19:13:51 +02:00
Matthias Beyer 44521a7c8c Dont use "return" keyword at end of function 2018-04-25 19:13:51 +02:00
Matthias Beyer dc18e650bb Collapse nested if-else-if 2018-04-25 19:13:51 +02:00
Matthias Beyer 84249e3fb5 Be less verbose when constructing an object
The rust compiler does some fancy things for us: It automatically finds
the right fields if the name of the variable and the file is the same.

Lets use that to reduce boilerplate with this patch.
2018-04-25 19:13:50 +02:00
Matthias Beyer 524c391ee0 Remove unused dependency 2018-04-24 22:16:40 +02:00
Matthias Beyer 563c76c375 Remove "stdio" file abstraction from store implementation 2018-04-24 22:16:40 +02:00
Matthias Beyer 19e0471f5b Remove tests with JsonMapper in backend 2018-04-24 22:16:40 +02:00
Matthias Beyer bae9188a08 Remove GlobStoreIdIterator helper iterator type 2018-04-24 13:40:42 +02:00
Matthias Beyer d70092d691 Remove: Store::retrieve_for_module 2018-04-24 13:40:42 +02:00
Matthias Beyer d2dceb6640 Update version numbers: 0.7.0 -> 0.8.0 2018-04-19 10:05:53 +02:00
Matthias Beyer 4568b1f625
Merge pull request #1380 from matthiasbeyer/minor
Minor patches
2018-04-18 16:46:41 +02:00
Matthias Beyer 98f8366e4c Fix documentation in crate metadata 2018-04-17 15:55:08 +02:00
Matthias Beyer 604f350340 Add logging in store 2018-04-14 16:55:36 +02:00
Matthias Beyer a769186cd7 Make iterator lifetimes less restricting 2018-04-07 13:55:54 +02:00
Matthias Beyer e61ccc9561 Fix: Entry::to_str() should return Result<_>
Because serializing might fail.

Also fixes all usages of the API.
2018-03-26 14:24:42 +02:00
Matthias Beyer 9e0d0d9f6c Add Entry::replace_from_buffer() 2018-03-23 15:44:34 +01:00
Matthias Beyer 7e623f39b8 Add message why panic
So we see that when grepping the source for `unimplemented!()`.
2018-03-23 10:05:58 +01:00
Matthias Beyer 41f7bab1c5 Fix: Store::create() should fail if the entry exists 2018-03-22 21:16:11 +01:00
Matthias Beyer 68ace5d147 Fix typo 2018-03-12 13:32:23 +01:00
Matthias Beyer da408b9e67 This fixes the file parsing (again)
Unfortunately, our latest fix to file parsing did not solve all issues.
So we have to fix it _again_.

The problem was the `std::str::Lines` iterator, which apparently fails
this:

    assert_eq!(1, "".lines().count());

as an empty line seems not to be a line.

Because of that, when reading a file with an empty line at its bottom
got stripped off that line.

This patch removes the use of the `lines()` iterator and uses
`split("\n")` instead. This only works on Unix operating systems, but as
we only target unix operating systems with imag, this is not considered
an issue right now.

This patch also adds extensive tests on multiple levels in the
`libimagstore` implementation:

* On the parsing level, for the function which implements the parsing
* On the filesystem abstraction levels
* On the `Store` levels

to make sure that everything is parsed correctly.
2018-03-10 14:53:15 +01:00
Matthias Beyer 579c00b62a Replace hard coded version strings with compiletime env 2018-03-06 12:45:41 +01:00
Matthias Beyer ee5a17790f Fix multi-line reading
Reading entries with multiple entries caused all lines to be read as one
line.

This bug is fixed with this patch.
2018-03-02 21:48:17 +01:00
Matthias Beyer 87d6f1221f Add testcase for reading multiple lines 2018-03-02 21:48:13 +01:00
Matthias Beyer 9fb5f453fe Rewrite entry parsing algorithm
Rewrite without regex crate.

The regex approach was broken. If the following _content_ was provided
in the entry:

    foo

    ---

    bar

The regex approach parsed the header until the "---" in the content.
This is, of course, not the way to do that.

Now, the parsing is implemented by hand. Should be faster as well,
though I don't care about this.

This fixes a severe bug.
2018-02-20 21:06:36 +01:00
Matthias Beyer 5f99018807 Simplify store debug print 2018-02-19 11:51:21 +01:00
Matthias Beyer 9e3c966d84
Merge pull request #1273 from matthiasbeyer/update-version-numbers
Update version string: 0.6.0 -> 0.7.0
2018-02-11 17:50:52 +01:00
Matthias Beyer 30d2c28a22 Update version string: 0.6.0 -> 0.7.0 2018-02-11 14:22:24 +01:00
Matthias Beyer 8fcd2a6c8c Prettify Store debug output implementation 2018-02-11 13:36:37 +01:00
Matthias Beyer d5a9e4930d Update dates in license header
And add missing header in one file
2018-02-07 02:48:53 +01:00
Matthias Beyer de613c9ebd
Merge pull request #1227 from matthiasbeyer/libimagentryutil/filtered-iterators
libimagentryutil: filtered iterators
2018-02-01 20:22:12 +01:00
Matthias Beyer 06cb8d50fb Make StoreId::is_in_collection() generic over AsRef<str> 2018-02-01 16:46:57 +01:00
Matthias Beyer b3f546129a Add StoreIdIteratorWithStore::without_store() 2018-02-01 16:46:38 +01:00
Matthias Beyer 8e931cd79f Change calls to into_get_iter() to not take argument 2018-02-01 16:46:38 +01:00
Matthias Beyer 3b01a9eb2f Add API in StoreIdIteratorWithStore to get acting iterators
This patch adds API functions in the StoreIdIteratorWithStore iterator
type to transform it into a iterator which _does_ something (as in the
`libimagstore::iter` API).

It mimics the API which is offered by `libimagstore::iter`.
2018-02-01 15:47:39 +01:00
Matthias Beyer 030e32e44f Provide StoreId Iterator which has a ref to the Store
This change is needed so we can refactor the "get" iterator to not take
an argument (the store) later, which improves the API.
2018-02-01 15:47:39 +01:00
Matthias Beyer 164b6b7f10 Move documentation to appropriate place 2018-01-29 09:38:32 +01:00
Matthias Beyer fcfc397fc8 env_logger: 0.5.0-rc.2 -> 0.5 2018-01-18 14:15:40 +01:00
Matthias Beyer 8d9c7dce4f env_logger: 0.5.0-rc.1 -> 0.5.0-rc.2 2018-01-15 11:22:09 +01:00
Matthias Beyer 635d000344 log: 0.4.0-rc.1 -> 0.4.0 2018-01-15 11:21:52 +01:00
Matthias Beyer c45130ddd0 env_logger: 0.4.* -> 0.5.0-rc.1 2018-01-15 11:20:27 +01:00
Matthias Beyer f209e12410 Update dependency: log: 0.3.* -> 0.4.0-rc.1 2018-01-15 11:20:07 +01:00
Matthias Beyer 3ef5fcfab6 libimagstore: Replace read with typed read 2018-01-13 01:14:03 +01:00
Matthias Beyer 0c4be78223 Update dependency: toml-query -> 0.6 2018-01-13 01:14:03 +01:00
Matthias Beyer bfc35e0517 Remove dependency "version"
Because the "version" crate is licensed as GPL, which would us require
to release imag as GPL, we remove the crate now.
2018-01-12 13:33:40 +01:00
Matthias Beyer 689310edfe Rename `Store::retrieve_copy` to `Store::get_copy`
The function was named falsely and nobody noticed. So nobody uses this
function yet - hopefully - as this change is a breaking API change.
2018-01-08 15:16:41 +01:00
Matthias Beyer 7d1d41884c Replace matching with function chaining 2018-01-05 11:37:09 +01:00
Matthias Beyer 774933ae4a
Merge pull request #1163 from matthiasbeyer/libimagstore/mighty-iters
libimagstore: More powerful iterator extensions
2017-12-25 22:02:56 +01:00
Matthias Beyer 9890371652
Merge pull request #1185 from matthiasbeyer/bump-version-strings
Update version strings: 0.5.0 -> 0.6.0
2017-12-25 21:06:14 +01:00
Matthias Beyer 46a8d373b3 Allow dead code in whole module 2017-12-25 19:23:41 +01:00
Matthias Beyer 7d67b67440 Update version strings in tests 2017-12-25 19:17:07 +01:00
Matthias Beyer 3c8dd19d11 Update version strings: 0.5.0 -> 0.6.0 2017-12-25 19:17:07 +01:00
Matthias Beyer 9128d04866 Remove test
This test is not applicable anymore because it tests (and tested) the
wrong thing.

It was to check whether the function failed because the "imag" key
contained the wrong type, but this is not tested by that function. The
function only checks whether the "imag" key is present.
2017-12-25 17:59:50 +01:00
Matthias Beyer 35410aaa2e Refactor: Remove unneccessary functions 2017-12-25 17:59:50 +01:00
Matthias Beyer 20a552f527 Refactor header checking to use toml-query 2017-12-25 17:59:50 +01:00
Matthias Beyer 2bf91fab09 Enhance error types 2017-12-25 17:59:50 +01:00
Matthias Beyer 0870665668 Add iterator extension for iterators over Result<T, E> 2017-12-24 13:52:50 +01:00
Matthias Beyer 67410b3ad2 Implement iter extension for all iterators over StoreId 2017-12-24 13:52:50 +01:00
Matthias Beyer 0ed636bb06 Refactor libimagrt+libimagstore to pass whole configuration object
Before we extracted the store configuration from the configuration
toml::Value object and passed it to the store.

This is unecessary overhead.

Now we pass the whole configuration object and let the store extract the
required values.
2017-12-24 13:52:18 +01:00
Matthias Beyer 174d8d76e9 Remove configuration member, reduce configuration
We only need the configuration to check whether creating the store
directory is actually allowed.
2017-12-24 13:52:13 +01:00
Matthias Beyer 38b56df406 Add new dependency: toml-query 2017-12-24 13:52:13 +01:00
Matthias Beyer af67ff51c8 Remove accidentially slipped-in println!() 2017-12-06 19:51:02 +01:00
Matthias Beyer 77f93e77f0 Fix syntax 2017-11-18 12:28:20 +01:00
Matthias Beyer dc26f8c20c
Merge pull request #1156 from matthiasbeyer/store-verify-from-cli-app
Move verify implementation from Store to CLI interface
2017-10-31 15:47:57 +01:00
Matthias Beyer a20871eb5e Add badges in Cargo.toml of all crates 2017-10-31 15:03:30 +01:00
Matthias Beyer 5d76e7bafa Use ? operator instead of try!() macro 2017-10-31 15:03:30 +01:00
Matthias Beyer 2855a89e24 Move verify implementation from Store to CLI interface 2017-10-31 13:11:34 +01:00
Matthias Beyer 16b5652fdd Remove accidentially slipped-in println 2017-10-15 19:49:06 +02:00
Matthias Beyer 23f4d7948f Fix Store::entries() to not yield directories
Before the iterator did also yield storeids for directories, which was a
bug.

This change introduces a new if_file() function in the store-internal
backend, which is needed to check whether a path actually points to a
File, be it inmemory or on the real filesystem.

That's because tests might fail if they check via PathBuf::is_file() as
in tests, the entries only exist inmemory.
2017-10-13 14:26:06 +02:00
Matthias Beyer 663242db7e Update dependency: error-chain: 0.10 -> 0.11 2017-10-12 22:12:27 +02:00
Matthias Beyer b587bbbdc1 Fix: Create directory before renaming file 2017-10-01 01:59:41 +02:00