Skip to content

Commit

Permalink
[rrd4j] Do not create RRD file when querying data (openhab#14961)
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Myers <mmyers75@icloud.com>
  • Loading branch information
lolodomo authored and matchews committed Aug 9, 2023
1 parent 3fc5c6f commit f33f092
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public void store(final Item item, @Nullable final String alias) {
private synchronized void internalStore(String name, double value, long now, boolean retry) {
RrdDb db = null;
try {
db = getDB(name);
db = getDB(name, true);
} catch (Exception e) {
logger.warn("Failed to open rrd4j database '{}' to store data ({})", name, e.toString());
}
Expand Down Expand Up @@ -276,10 +276,11 @@ public Iterable<HistoricItem> query(FilterCriteria filter) {
logger.warn("Item name is missing in filter {}", filter);
return List.of();
}
logger.trace("Querying rrd4j database for item '{}'", itemName);

RrdDb db = null;
try {
db = getDB(itemName);
db = getDB(itemName, false);
} catch (Exception e) {
logger.warn("Failed to open rrd4j database '{}' for querying ({})", itemName, e.toString());
return List.of();
Expand Down Expand Up @@ -378,7 +379,7 @@ public Set<PersistenceItemInfo> getItemInfo() {
return Set.of();
}

protected synchronized @Nullable RrdDb getDB(String alias) {
protected synchronized @Nullable RrdDb getDB(String alias, boolean createFileIfAbsent) {
RrdDb db = null;
Path path = getDatabasePath(alias);
try {
Expand All @@ -389,7 +390,7 @@ public Set<PersistenceItemInfo> getItemInfo() {
// recreate the RrdDb instance from the file
builder.setPath(path.toString());
db = builder.build();
} else {
} else if (createFileIfAbsent) {
if (!Files.exists(DB_FOLDER)) {
Files.createDirectories(DB_FOLDER);
}
Expand Down

0 comments on commit f33f092

Please sign in to comment.