Commit 9b1c9b76 authored by Jean-Benoist Leger's avatar Jean-Benoist Leger

lmdb_rewriter

parent 717239ea
......@@ -3,14 +3,17 @@ CC=g++
CXXFLAGS=-O2 -std=c++11
#LDFLAGS=-g -Wall
LDFLAGS=-O2 -fwhole-program -flto
LDLIBS_LMDB=-llmdb
LDLIBS_LMDB=-llmdb -lpthread
LDLIBS_PQXX=-lpqxx
LDLIBS_OSMPBF=-L/home/rv/osmpbf/osmpbf -losmpbf -lprotobuf -lz
INCLUDE_OSMPBF=-I/home/rv/osmpbf -I/home/rv/osmpbf/osmpbf/include
LDLIBS_OSMPBF=-L../../osmpbf/osmpbf -losmpbf -lprotobuf -lz
INCLUDE_OSMPBF=-I../../osmpbf -I../../osmpbf/osmpbf/include
.PHONY: clean
all: elevation_create_database elevation_query_database route_create_databases route_query_nodes_database route_query_lookup_database route route_create_databases_from_pbf
all: elevation_create_database elevation_query_database route_query_nodes_database route_query_lookup_database route route_create_databases_from_pbf lmdb_rewriter
lmdb_rewriter: lmdb_rewriter.o
$(CC) -static $(LDFLAGS) -o $@ $+ $(LDLIBS_LMDB)
elevation_create_database: elevation.o elevation_create_database.o
$(CC) $(LDFLAGS) -o $@ $+ $(LDLIBS_LMDB)
......@@ -33,6 +36,9 @@ route: route.o route_db.o lookup.o functions.o nodes_db.o lookup_db.o conv_funct
route_create_databases_from_pbf: route_create_databases_from_pbf.o lookup_db.o nodes_db.o elevation.o parse_way.o conv_functions.o
$(CC) $(LDFLAGS) -o $@ $+ $(LDLIBS_LMDB) $(LDLIBS_OSMPBF)
lmdb_rewriter.o: lmdb_rewriter.cc conf.h
$(CC) $(CXXFLAGS) -c $< -o $@
elevation.o: elevation.cc elevation.h conf.h
$(CC) $(CXXFLAGS) -c $< -o $@
......
#include <stdio.h>
#include <stdlib.h>
#include <lmdb.h>
#include "conf.h"
#include <sys/stat.h>
int main(int argc, char ** argv)
{
if(argc<2)
{
fprintf(stderr,"Udage: %s original_db_path/ copy_db_path/\n",argv[0]);
abort();
}
char zfilename[RV_ZCHAR_LENGTH];
snprintf(zfilename,RV_ZCHAR_LENGTH,"%s/data.mdb",argv[2]);
remove(zfilename);
snprintf(zfilename,RV_ZCHAR_LENGTH,"%s/lock.mdb",argv[2]);
remove(zfilename);
mkdir(argv[2],0755);
int rc;
MDB_env *env1;
MDB_dbi dbi1;
MDB_txn *txn1;
MDB_cursor *cursor1;
rc = mdb_env_create(&env1);
if(rc)
{
fprintf(stderr, "mdb_env_create: (%d) %s\n", rc, mdb_strerror(rc));
abort();
}
rc = mdb_env_set_mapsize(env1, RV_MAXIMUM_LMDB_SIZE);
if(rc)
{
fprintf(stderr, "mdb_env_set_mapsize: (%d) %s\n", rc, mdb_strerror(rc));
abort();
}
rc = mdb_env_open(env1, argv[1], 0, 0644);
if(rc)
{
fprintf(stderr, "mdb_env_open: (%d) %s\n", rc, mdb_strerror(rc));
abort();
}
rc = mdb_txn_begin(env1, NULL, MDB_RDONLY, &txn1);
if(rc)
{
fprintf(stderr, "mdb_txn_begin: (%d) %s\n", rc, mdb_strerror(rc));
abort();
}
rc = mdb_dbi_open(txn1, NULL, 0, &dbi1);
if(rc)
{
fprintf(stderr, "mdb_dbi_open: (%d) %s\n", rc, mdb_strerror(rc));
abort();
}
MDB_env *env2;
MDB_dbi dbi2;
MDB_txn *txn2;
rc = mdb_env_create(&env2);
if(rc)
{
fprintf(stderr, "mdb_env_create: (%d) %s\n", rc, mdb_strerror(rc));
abort();
}
rc = mdb_env_set_mapsize(env2, RV_MAXIMUM_LMDB_SIZE);
if(rc)
{
fprintf(stderr, "mdb_env_set_mapsize: (%d) %s\n", rc, mdb_strerror(rc));
abort();
}
rc = mdb_env_open(env2, argv[2], 0, 0644);
if(rc)
{
fprintf(stderr, "mdb_env_open: (%d) %s\n", rc, mdb_strerror(rc));
abort();
}
rc = mdb_txn_begin(env2, NULL, 0, &txn2);
if(rc)
{
fprintf(stderr, "mdb_txn_begin: (%d) %s\n", rc, mdb_strerror(rc));
abort();
}
rc = mdb_dbi_open(txn2, NULL, 0, &dbi2);
if(rc)
{
fprintf(stderr, "mdb_dbi_open: (%d) %s\n", rc, mdb_strerror(rc));
abort();
}
MDB_val key, data;
rc = mdb_cursor_open(txn1, dbi1, &cursor1);
while ((rc = mdb_cursor_get(cursor1, &key, &data, MDB_NEXT)) == 0)
{
rc = mdb_put(txn2, dbi2, &key, &data, 0);
if(rc)
{
fprintf(stderr, "mdb_put: (%d) %s\n", rc, mdb_strerror(rc));
abort();
}
}
mdb_cursor_close(cursor1);
mdb_txn_abort(txn1);
mdb_close(env1, dbi1);
mdb_env_close(env1);
mdb_txn_commit(txn2);
mdb_close(env2, dbi2);
mdb_env_close(env2);
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment