Skip to content

Commit

Permalink
multiengine support
Browse files Browse the repository at this point in the history
:Release Notes:

:Detailed Notes:
Add engine factories auto-registration
Add support for multi-engines testing

:Testing Performed:
Tested on desktop

:QA Notes:

:Issues Addressed:
[BHV-2627] [DB8] Switch to a single LevelDB file per database

Open-webOS-DCO-1.0-Signed-off-by: Nikolay Orliuk <nikolay.orliuk@lge.com>
Open-webOS-DCO-1.0-Signed-off-by: Oleksandr Solomakha <oleksander.solomakha@lge.com>

Change-Id: I3b40539c2e88ec987e744b75c5eeaed779a3ba1a
Reviewed-on: https://g2g.palm.com/5535
Reviewed-by: DCO Verification
Reviewed-by: Olexandr Solomakha <oleksander.solomakha@lge.com>
Tested-by: Olexandr Solomakha <oleksander.solomakha@lge.com>
  • Loading branch information
Nikolay Orliuk authored and Olexandr Solomakha committed May 5, 2014
1 parent 5af0c64 commit 719d460
Show file tree
Hide file tree
Showing 22 changed files with 183 additions and 238 deletions.
14 changes: 8 additions & 6 deletions CMakeLists.txt
Expand Up @@ -28,6 +28,9 @@ webos_component(3 2 0)

include(FindPkgConfig)

# -- add local include paths (should override already installed ones)
include_directories(inc)

# -- check for glib 2.0
pkg_check_modules(GLIB2 REQUIRED glib-2.0)
include_directories(${GLIB2_INCLUDE_DIRS})
Expand Down Expand Up @@ -82,9 +85,6 @@ webos_add_compiler_flags(ALL -Wall -fPIC -Wconversion --std=c++0x
webos_add_compiler_flags(DEBUG -DMOJ_DEBUG)
webos_add_linker_options(ALL --no-undefined)

# -- add local include paths
include_directories(inc)

# -- source for generating libmojocore.so
set(CORE_LIB_SOURCES
src/core/MojApp.cpp
Expand Down Expand Up @@ -269,9 +269,11 @@ if (WEBOS_CONFIG_BUILD_TESTS)
add_subdirectory(bundled/gtest-1.6.0)
add_subdirectory(test/mojocore)
add_subdirectory(test/db-core)
if (WEBOS_DB8_BACKEND STREQUAL "leveldb")
add_subdirectory(test/leveldb)
endif ()
foreach (backend ${WEBOS_DB8_BACKEND})
if (backend STREQUAL "leveldb")
add_subdirectory(test/leveldb)
endif ()
endforeach ()
#add_subdirectory(test/db-media)

include(ProcessorCount)
Expand Down
6 changes: 5 additions & 1 deletion README.md
Expand Up @@ -155,10 +155,14 @@ From the directory where you originally ran `make install`, enter:

You will need to use `sudo` if you did not specify `WEBOS_INSTALL_ROOT`.

#### Running

If DB8 compiled with several backends you'll need to specify one in environment variable MOJODB_ENGINE .

# Copyright and License Information

All content, including all source code files and documentation files in this repository are:
Copyright (c) 2009-2013 LG Electronics, Inc.
Copyright (c) 2009-2014 LG Electronics, Inc.

All content, including all source code files and documentation files in this repository are:
Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
29 changes: 27 additions & 2 deletions inc/db/MojDbStorageEngine.h
@@ -1,6 +1,6 @@
/* @@@LICENSE
*
* Copyright (c) 2009-2013 LG Electronics, Inc.
* Copyright (c) 2009-2014 LG Electronics, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,12 +20,15 @@
#ifndef MOJDBSTORAGEENGINE_H_
#define MOJDBSTORAGEENGINE_H_

#include <utility>

#include "db/MojDbDefs.h"
#include "db/MojDbWatcher.h"
#include "db/MojDbQuotaEngine.h"
#include "core/MojAutoPtr.h"
#include "core/MojObject.h"
#include "core/MojVector.h"
#include "core/MojHashMap.h"
#include "core/MojSignal.h"

class MojDbEnv : public MojRefCounted
Expand Down Expand Up @@ -191,10 +194,13 @@ class MojDbStorageEngineFactory : public MojRefCounted
class MojDbStorageEngine : public MojRefCounted
{
public:
typedef MojRefCountedPtr<MojDbStorageEngineFactory> Factory;

static MojErr createDefaultEngine(MojRefCountedPtr<MojDbStorageEngine>& engineOut);
static MojErr createEngine(const MojChar* name, MojRefCountedPtr<MojDbStorageEngine>& engineOut);
static MojErr createEnv(MojRefCountedPtr<MojDbEnv>& envOut) { return m_factory->createEnv(envOut); };
static MojErr setEngineFactory(MojDbStorageEngineFactory* factory);
static MojErr setEngineFactory(const MojChar *name);
static const MojDbStorageEngineFactory* engineFactory() {return m_factory.get();};

virtual ~MojDbStorageEngine() {}
Expand All @@ -210,8 +216,27 @@ class MojDbStorageEngine : public MojRefCounted

protected:
MojDbStorageEngine();
static MojRefCountedPtr<MojDbStorageEngineFactory> m_factory;

typedef MojHashMap<MojString, Factory> Factories;

private:
static Factory m_factory;
static Factories m_factories;

public:
template <typename T>
struct Registrator
{
template<typename... Args>
Registrator(Args &&... args)
{
Factory factory { new T(std::forward<args>...) };
MojAssert(factory.get());
MojString key;
if (key.assign(factory->name()) != MojErrNone) return; // ignore invalid name
m_factories.put(key, factory);
}
};
};


Expand Down
106 changes: 55 additions & 51 deletions src/db-luna/BackendBuildRules.cmake
Expand Up @@ -24,67 +24,71 @@
# Optional variable:
# DB_BACKEND_WRAPPER_CFLAGS - compiller flags

set(WEBOS_DB8_BACKEND "leveldb" CACHE STRING "Backend to use with DB8")
set(WEBOS_DB8_BACKEND "leveldb" CACHE STRING "Backend(s) to use with DB8")

message (STATUS "Use database frontend: ${WEBOS_DB8_BACKEND}")
foreach (backend ${WEBOS_DB8_BACKEND})
message (STATUS "Use database frontend: ${backend}")

if (WEBOS_DB8_BACKEND STREQUAL "berkeleydb")
# -- check for BerkeleyDB
# (add an alternate standard path in case building BDB locally: does not override)
find_library(BDB NAMES db-4.8 PATH /usr/local/BerkeleyDB.4.8/lib)
if(BDB STREQUAL "BDB-NOTFOUND")
MESSAGE(FATAL_ERROR "Failed to find BerkleyDB libaries. Please install.")
endif()
if (backend STREQUAL "berkeleydb")
# -- check for BerkeleyDB
# (add an alternate standard path in case building BDB locally: does not override)
find_library(BDB NAMES db-4.8 PATH /usr/local/BerkeleyDB.4.8/lib)
if(BDB STREQUAL "BDB-NOTFOUND")
MESSAGE(FATAL_ERROR "Failed to find BerkleyDB libaries. Please install.")
endif()

find_path(BDB_INC db.h
PATHS /usr/local/BerkeleyDB.4.8/include
PATH_SUFFIXES db4.8)
if(BDB_INC STREQUAL "BDB_INC-NOTFOUND")
MESSAGE(FATAL_ERROR "Failed to find BerkleyDB includes. Please install.")
endif()
find_path(BDB_INC db.h
PATHS /usr/local/BerkeleyDB.4.8/include
PATH_SUFFIXES db4.8)
if(BDB_INC STREQUAL "BDB_INC-NOTFOUND")
MESSAGE(FATAL_ERROR "Failed to find BerkleyDB includes. Please install.")
endif()

set (DB_BACKEND_INCLUDES "${BDB_INC}")
set (DB_BACKEND_LIB "${BDB}")
set (DB_BACKEND_INCLUDES ${DB_BACKEND_INCLUDES} ${BDB_INC})
set (DB_BACKEND_LIB ${DB_BACKEND_LIB} ${BDB})

set(DB_BACKEND_WRAPPER_SOURCES
src/db-luna/MojDbBerkeleyEngine.cpp
src/db-luna/MojDbBerkeleyFactory.cpp
src/db-luna/MojDbBerkeleyQuery.cpp
)
set(DB_BACKEND_WRAPPER_SOURCES
${DB_BACKEND_WRAPPER_SOURCES}
src/db-luna/MojDbBerkeleyEngine.cpp
src/db-luna/MojDbBerkeleyFactory.cpp
src/db-luna/MojDbBerkeleyQuery.cpp
)

set (DB_BACKEND_WRAPPER_CFLAGS "-DMOJ_USE_BDB")
elseif (WEBOS_DB8_BACKEND STREQUAL "leveldb")
set (DB_BACKEND_WRAPPER_CFLAGS "${DB_BACKEND_WRAPPER_CFLAGS} -DMOJ_USE_BDB")
elseif (backend STREQUAL "leveldb")

# -- check for LevelDB backend
find_library(LDB NAMES leveldb ${WEBOS_INSTALL_ROOT}/lib)
if(LDB STREQUAL "LDB-NOTFOUND")
MESSAGE(FATAL_ERROR "Failed to find LevelDB libaries. Please install.")
endif()
# -- check for LevelDB backend
find_library(LDB NAMES leveldb ${WEBOS_INSTALL_ROOT}/lib)
if(LDB STREQUAL "LDB-NOTFOUND")
MESSAGE(FATAL_ERROR "Failed to find LevelDB libaries. Please install.")
endif()

set (DB_BACKEND_INCLUDES ${WEBOS_INSTALL_ROOT}/include)
set (DB_BACKEND_LIB "${LDB}")
set (DB_BACKEND_INCLUDES ${DB_BACKEND_INCLUDES} ${WEBOS_INSTALL_ROOT}/include)
set (DB_BACKEND_LIB ${DB_BACKEND_LIB} ${LDB})

set(DB_BACKEND_WRAPPER_SOURCES
src/db-luna/leveldb/defs.cpp
src/db-luna/leveldb/MojDbLevelEngine.cpp
src/db-luna/leveldb/MojDbLevelFactory.cpp
src/db-luna/leveldb/MojDbLevelDatabase.cpp
src/db-luna/leveldb/MojDbLevelQuery.cpp
src/db-luna/leveldb/MojDbLevelTxn.cpp
src/db-luna/leveldb/MojDbLevelSeq.cpp
src/db-luna/leveldb/MojDbLevelCursor.cpp
src/db-luna/leveldb/MojDbLevelEnv.cpp
src/db-luna/leveldb/MojDbLevelIndex.cpp
src/db-luna/leveldb/MojDbLevelItem.cpp
src/db-luna/leveldb/MojDbLevelTxnIterator.cpp
src/db-luna/leveldb/MojDbLevelIterator.cpp
src/db-luna/leveldb/MojDbLevelContainerIterator.cpp
)
set(DB_BACKEND_WRAPPER_SOURCES
${DB_BACKEND_WRAPPER_SOURCES}
src/db-luna/leveldb/defs.cpp
src/db-luna/leveldb/MojDbLevelEngine.cpp
src/db-luna/leveldb/MojDbLevelFactory.cpp
src/db-luna/leveldb/MojDbLevelDatabase.cpp
src/db-luna/leveldb/MojDbLevelQuery.cpp
src/db-luna/leveldb/MojDbLevelTxn.cpp
src/db-luna/leveldb/MojDbLevelSeq.cpp
src/db-luna/leveldb/MojDbLevelCursor.cpp
src/db-luna/leveldb/MojDbLevelEnv.cpp
src/db-luna/leveldb/MojDbLevelIndex.cpp
src/db-luna/leveldb/MojDbLevelItem.cpp
src/db-luna/leveldb/MojDbLevelTxnIterator.cpp
src/db-luna/leveldb/MojDbLevelIterator.cpp
src/db-luna/leveldb/MojDbLevelContainerIterator.cpp
)

set (DB_BACKEND_WRAPPER_CFLAGS "-DMOJ_USE_LDB")
else ()
message(FATAL_ERROR "WEBOS_DB8_BACKEND: unsuported value '${WEBOS_DB8_BACKEND}'")
endif ()
set (DB_BACKEND_WRAPPER_CFLAGS "${DB_BACKEND_WRAPPER_CFLAGS} -DMOJ_USE_LDB")
else ()
message(FATAL_ERROR "WEBOS_DB8_BACKEND: unsuported value '${backend}'")
endif ()
endforeach ()

# -- check for errors
if(NOT DEFINED DB_BACKEND_LIB)
Expand Down
8 changes: 3 additions & 5 deletions src/db-luna/MojDbBerkeleyEngine.cpp
@@ -1,6 +1,6 @@
/* @@@LICENSE
*
* Copyright (c) 2009-2013 LG Electronics, Inc.
* Copyright (c) 2009-2014 LG Electronics, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -861,12 +861,12 @@ MojErr MojDbBerkeleyEnv::translateErr(int dbErr)

void MojDbBerkeleyEnv::errcall(const DB_ENV *dbenv, const char *errpfx, const char *msg)
{
LOG_ERROR(MSGID_ERROR_CALL, 1, PMLOGKS("bdb", msg), "");
LOG_ERROR(MSGID_ERROR_CALL, 1, PMLOGKS("berkeleydb", msg), "");
}

void MojDbBerkeleyEnv::msgcall(const DB_ENV *dbenv, const char *msg)
{
LOG_ERROR(MSGID_MESSAGE_CALL, 1, PMLOGKS("bdb", msg), "");
LOG_ERROR(MSGID_MESSAGE_CALL, 1, PMLOGKS("berkeleydb", msg), "");
}

MojDbBerkeleyEngine::MojDbBerkeleyEngine()
Expand Down Expand Up @@ -992,8 +992,6 @@ MojErr MojDbBerkeleyEngine::compact()

struct statvfs statAtBeginning, statAfterCompact, statAtEnd;

MojLogTrace(MojDbBerkeleyEngine::s_log);

struct timeval totalStartTime = {0,0}, totalStopTime = {0,0};

gettimeofday(&totalStartTime, NULL);
Expand Down
7 changes: 5 additions & 2 deletions src/db-luna/MojDbBerkeleyFactory.cpp
@@ -1,6 +1,6 @@
/* @@@LICENSE
*
* Copyright (c) 2009-2013 LG Electronics, Inc.
* Copyright (c) 2009-2014 LG Electronics, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,9 +17,12 @@
* LICENSE@@@ */


#include "core/MojLogDb8.h"
#include "db-luna/MojDbBerkeleyFactory.h"
#include "db-luna/MojDbBerkeleyEngine.h"

namespace { MojDbStorageEngine::Registrator<MojDbBerkeleyFactory> factoryBerkeleyDB; }

MojErr MojDbBerkeleyFactory::create(MojRefCountedPtr<MojDbStorageEngine>& engineOut) const
{
LOG_TRACE("Entering function %s", __FUNCTION__);
Expand All @@ -39,4 +42,4 @@ MojErr MojDbBerkeleyFactory::createEnv(MojRefCountedPtr<MojDbEnv>& envOut) const
return MojErrNone;
}

const MojChar* MojDbBerkeleyFactory::name() const {return _T("bdb");};
const MojChar* MojDbBerkeleyFactory::name() const {return _T("berkeleydb");};
3 changes: 2 additions & 1 deletion src/db-luna/MojDbBerkeleyQuery.cpp
@@ -1,6 +1,6 @@
/* @@@LICENSE
*
* Copyright (c) 2009-2013 LG Electronics, Inc.
* Copyright (c) 2009-2014 LG Electronics, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,6 +17,7 @@
* LICENSE@@@ */


#include "core/MojLogDb8.h"
#include "db-luna/MojDbBerkeleyQuery.h"
#include "db-luna/MojDbBerkeleyEngine.h"
#include "db/MojDbQueryPlan.h"
Expand Down
16 changes: 0 additions & 16 deletions src/db-luna/MojDbLunaServiceApp.cpp
Expand Up @@ -21,14 +21,6 @@
#include "db/MojDbServiceDefs.h"
#include "db/MojDbServiceHandler.h"

#ifdef MOJ_USE_BDB
#include "db-luna/MojDbBerkeleyFactory.h"
#elif MOJ_USE_LDB
#include "db-luna/leveldb/MojDbLevelFactory.h"
#else
#error "Set database type"
#endif

#ifndef MOJ_VERSION_STRING
#define MOJ_VERSION_STRING NULL
#endif
Expand All @@ -46,14 +38,6 @@ MojDbLunaServiceApp::MojDbLunaServiceApp()
: MojReactorApp<MojGmainReactor>(MajorVersion, MinorVersion, VersionString)
, m_mainService(m_dispatcher)
{
// set up db first
#ifdef MOJ_USE_BDB
MojDbStorageEngine::setEngineFactory(new MojDbBerkeleyFactory());
#elif MOJ_USE_LDB
MojDbStorageEngine::setEngineFactory(new MojDbLevelFactory());
#else
#error "Database not set"
#endif
}

MojDbLunaServiceApp::~MojDbLunaServiceApp()
Expand Down
6 changes: 4 additions & 2 deletions src/db-luna/leveldb/MojDbLevelFactory.cpp
@@ -1,6 +1,6 @@
/* @@@LICENSE
*
* Copyright (c) 2009-2013 LG Electronics, Inc.
* Copyright (c) 2009-2014 LG Electronics, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,6 +20,8 @@
#include "db-luna/leveldb/MojDbLevelEngine.h"
#include "db-luna/leveldb/MojDbLevelEnv.h"

namespace { MojDbStorageEngine::Registrator<MojDbLevelFactory> factoryLevelDB; }

MojErr MojDbLevelFactory::create(MojRefCountedPtr<MojDbStorageEngine>& engineOut) const
{
LOG_TRACE("Entering function %s", __FUNCTION__);
Expand All @@ -38,4 +40,4 @@ MojErr MojDbLevelFactory::createEnv(MojRefCountedPtr<MojDbEnv>& envOut) const
return MojErrNone;
}

const MojChar* MojDbLevelFactory::name() const { return _T("ldb"); }
const MojChar* MojDbLevelFactory::name() const { return _T("leveldb"); }
3 changes: 1 addition & 2 deletions src/db/MojDb.cpp
@@ -1,6 +1,6 @@
/* @@@LICENSE
*
* Copyright (c) 2009-2013 LG Electronics, Inc.
* Copyright (c) 2009-2014 LG Electronics, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -31,7 +31,6 @@
#include "core/MojObjectSerialization.h"
#include "core/MojTime.h"
#include "core/MojFile.h"
#include "db-luna/leveldb/MojDbLevelItem.h"

const MojChar* const MojDb::AdminRole = _T("admin");
const MojChar* const MojDb::ObjDbName = _T("objects.db");
Expand Down

0 comments on commit 719d460

Please sign in to comment.