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

ignore --shard-stores if --compact is present #660

Merged
merged 2 commits into from
Jan 28, 2024
Merged
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
4 changes: 2 additions & 2 deletions include/node_stores.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ class CompactNodeStore : public NodeStore
void batchStart() override {}

// CompactNodeStore has no metadata to know whether or not it contains
// a node, so it's not suitable for used in sharded scenarios.
bool contains(size_t shard, NodeID id) const override { return true; }
// a node, so it's not suitable for use in sharded scenarios
bool contains(size_t shard, NodeID id) const override { throw std::runtime_error("CompactNodeStore does not support contains"); }
NodeStore& shard(size_t shard) override { return *this; }
const NodeStore& shard(size_t shard) const override { return *this; }
size_t shards() const override { return 1; }
Expand Down
1 change: 1 addition & 0 deletions include/osm_store.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ class OSMStore
void open(std::string const &osm_store_filename);

void use_compact_store(bool use) { use_compact_nodes = use; }
bool isCompactStore() { return use_compact_nodes; }
void enforce_integrity(bool ei) { require_integrity = ei; }
bool integrity_enforced() { return require_integrity; }

Expand Down
2 changes: 2 additions & 0 deletions include/pbf_processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#ifndef _READ_PBF_H
#define _READ_PBF_H

#include <atomic>
#include <string>
#include <unordered_set>
#include <vector>
Expand Down Expand Up @@ -122,6 +123,7 @@ class PbfProcessor

OSMStore &osmStore;
std::mutex ioMutex;
std::atomic<bool> compactWarningIssued;
};

int ReadPbfBoundingBox(const std::string &inputFile, double &minLon, double &maxLon,
Expand Down
11 changes: 10 additions & 1 deletion src/pbf_processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ std::atomic<uint64_t> blocksProcessed(0), blocksToProcess(0);
thread_local PbfReader::PbfReader reader;

PbfProcessor::PbfProcessor(OSMStore &osmStore)
: osmStore(osmStore)
: osmStore(osmStore), compactWarningIssued(false)
{ }

bool PbfProcessor::ReadNodes(OsmLuaProcessing& output, PbfReader::PrimitiveGroup& pg, const PbfReader::PrimitiveBlock& pb, const SignificantTags& nodeKeys)
Expand All @@ -31,8 +31,17 @@ bool PbfProcessor::ReadNodes(OsmLuaProcessing& output, PbfReader::PrimitiveGroup
TagMap tags;


bool isCompactStore = osmStore.isCompactStore();
NodeID lastNodeId = 0;
for (auto& node : pg.nodes()) {
NodeID nodeId = node.id;
if (isCompactStore && lastNodeId != 0 && nodeId != lastNodeId + 1 && !compactWarningIssued.exchange(true)) {
std::lock_guard<std::mutex> lock(ioMutex);
std::cout << "warning: --compact mode enabled, but PBF has gaps in IDs" << std::endl;
std::cout << " to fix: osmium renumber your-file.osm.pbf -o renumbered.osm.pbf" << std::endl;
}
lastNodeId = nodeId;

LatpLon latplon = { int(lat2latp(double(node.lat)/10000000.0)*10000000.0), node.lon };

tags.reset();
Expand Down
4 changes: 3 additions & 1 deletion src/tilemaker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,9 @@ int main(const int argc, const char* argv[]) {

shared_ptr<NodeStore> nodeStore;

if (options.osm.shardStores) {
// CompactNodeStore is a dense datatype; it doesn't make sense to allocate
// more than one of them.
if (options.osm.shardStores && !options.osm.compact) {
nodeStore = std::make_shared<ShardedNodeStore>(createNodeStore);
} else {
nodeStore = createNodeStore();
Expand Down
Loading