├── vagrant ├── .vagrant │ └── machines │ │ └── default │ │ └── virtualbox │ │ ├── creator_uid │ │ ├── action_set_name │ │ ├── id │ │ ├── index_uuid │ │ ├── action_provision │ │ ├── synced_folders │ │ └── private_key ├── res │ └── liboss.so ├── id_rsa.pub ├── vagrant-setup.sh ├── vagrant-ssh.sh ├── id_rsa └── Vagrantfile ├── sample └── CMakeLists.txt ├── docs ├── open-file.png ├── read-data.png ├── ssdkv-evict.jpg ├── ssdkv-evict.png ├── write-data.png ├── bucket_structure.jpg ├── bucket_structure.png ├── create-context.pdf ├── create-context.png ├── ssdkv-read-write.jpg └── ssdkv-read-write.png ├── test ├── data │ ├── .gitignore │ └── datagen.sh ├── performance │ └── .gitignore ├── function │ ├── TapeSort │ │ ├── src │ │ │ ├── dbtproj.cpp │ │ │ ├── sortBuffer.h │ │ │ ├── recordOps.cpp │ │ │ ├── fileOps.h │ │ │ ├── dbtproj.h │ │ │ ├── recordPtr.h │ │ │ ├── recordPtr.cpp │ │ │ ├── main.cpp │ │ │ ├── recordOps.h │ │ │ └── bufferOps.h │ │ ├── README.md │ │ ├── CMakeLists.txt │ │ └── bootstrap │ ├── HashJoin │ │ ├── README.md │ │ ├── src │ │ │ ├── dbtproj.cpp │ │ │ ├── HashJoin.h │ │ │ ├── recordOps.cpp │ │ │ ├── fileOps.h │ │ │ ├── recordPtr.h │ │ │ ├── recordPtr.cpp │ │ │ └── dbtproj.h │ │ ├── CMakeLists.txt │ │ └── bootstrap │ ├── FunctionTestMain.cpp │ ├── CMakeLists.txt │ └── TestCInterface.cpp └── CMakeLists.txt ├── CMake ├── CMakeTestCompileSteadyClock.cpp ├── CMakeTestCompileNestedException.cpp ├── CMakeTestCompileStrerror.cpp ├── FindLiboss.cmake ├── Functions.cmake ├── Platform.cmake └── CodeCoverage.cmake ├── config.properties ├── mock ├── CMakeLists.txt └── TestUtil.h ├── .gitignore ├── src ├── libgopherwood.pc ├── libgopherwood.pc.in ├── platform.h.in ├── common │ ├── Exception.cpp │ ├── StackPrinter.h │ ├── Thread.cpp │ ├── Memory.h │ ├── Function.h │ ├── Unordered.h │ ├── OssBuilder.h │ ├── Configuration.h │ ├── Configuration.cpp │ ├── Logger.h │ ├── DateTime.h │ ├── ObjectStorInfo.h │ ├── Thread.h │ ├── Hash.cpp │ ├── ThreadPool.h │ ├── Logger.cpp │ └── Hash.h ├── block │ ├── LocalBlockReader.h │ ├── LocalBlockReader.cpp │ ├── LocalBlockWriter.cpp │ ├── OssBlockWorker.h │ ├── LocalBlockWriter.h │ ├── BlockInputStream.h │ ├── BlockOutputStream.h │ ├── BlockInputStream.cpp │ └── BlockOutputStream.cpp ├── network │ └── Syscall.h ├── core │ ├── AdminActiveStatus.h │ ├── BaseActiveStatus.cpp │ ├── BaseActiveStatus.h │ ├── SharedMemoryManager.h │ ├── ActiveStatusContext.h │ ├── BlockStatus.cpp │ ├── BlockStatus.h │ └── ActiveStatusContext.cpp └── file │ ├── InputStream.h │ ├── OutputStream.h │ ├── FileId.h │ ├── File.h │ ├── FileSystem.h │ ├── InputStream.cpp │ ├── OutputStream.cpp │ └── File.cpp ├── gtest ├── CMakeLists.txt ├── include │ └── gtest │ │ └── gtest_prod.h └── src │ └── gtest-typed-test.cc ├── gmock ├── CMakeLists.txt ├── COPYING └── include │ └── gmock │ ├── gmock-more-matchers.h │ ├── internal │ └── gmock-port.h │ └── gmock.h ├── CMakeLists-bak.txt ├── CMakeLists.txt ├── README.md └── bootstrap /vagrant/.vagrant/machines/default/virtualbox/creator_uid: -------------------------------------------------------------------------------- 1 | 0 -------------------------------------------------------------------------------- /sample/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | CMAKE_MINIMUM_REQUIRED(VERSION 2.8) 2 | -------------------------------------------------------------------------------- /vagrant/.vagrant/machines/default/virtualbox/action_set_name: -------------------------------------------------------------------------------- 1 | 1510724197 -------------------------------------------------------------------------------- /vagrant/.vagrant/machines/default/virtualbox/id: -------------------------------------------------------------------------------- 1 | bda3d2d6-0eb6-414a-a07e-3766bb33f9f6 -------------------------------------------------------------------------------- /vagrant/.vagrant/machines/default/virtualbox/index_uuid: -------------------------------------------------------------------------------- 1 | c00c96fa2a92411e825329e83fe7ee03 -------------------------------------------------------------------------------- /docs/open-file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashDataInc/Gopherwood/HEAD/docs/open-file.png -------------------------------------------------------------------------------- /docs/read-data.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashDataInc/Gopherwood/HEAD/docs/read-data.png -------------------------------------------------------------------------------- /docs/ssdkv-evict.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashDataInc/Gopherwood/HEAD/docs/ssdkv-evict.jpg -------------------------------------------------------------------------------- /docs/ssdkv-evict.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashDataInc/Gopherwood/HEAD/docs/ssdkv-evict.png -------------------------------------------------------------------------------- /docs/write-data.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashDataInc/Gopherwood/HEAD/docs/write-data.png -------------------------------------------------------------------------------- /vagrant/.vagrant/machines/default/virtualbox/action_provision: -------------------------------------------------------------------------------- 1 | 1.5:bda3d2d6-0eb6-414a-a07e-3766bb33f9f6 -------------------------------------------------------------------------------- /vagrant/res/liboss.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashDataInc/Gopherwood/HEAD/vagrant/res/liboss.so -------------------------------------------------------------------------------- /docs/bucket_structure.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashDataInc/Gopherwood/HEAD/docs/bucket_structure.jpg -------------------------------------------------------------------------------- /docs/bucket_structure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashDataInc/Gopherwood/HEAD/docs/bucket_structure.png -------------------------------------------------------------------------------- /docs/create-context.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashDataInc/Gopherwood/HEAD/docs/create-context.pdf -------------------------------------------------------------------------------- /docs/create-context.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashDataInc/Gopherwood/HEAD/docs/create-context.png -------------------------------------------------------------------------------- /docs/ssdkv-read-write.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashDataInc/Gopherwood/HEAD/docs/ssdkv-read-write.jpg -------------------------------------------------------------------------------- /docs/ssdkv-read-write.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashDataInc/Gopherwood/HEAD/docs/ssdkv-read-write.png -------------------------------------------------------------------------------- /test/data/.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore everything in this directory 2 | * 3 | # Except this file 4 | !.gitignore 5 | -------------------------------------------------------------------------------- /test/performance/.gitignore: -------------------------------------------------------------------------------- 1 | /hello.cpp 2 | /hello.sh 3 | /hello 4 | /CMetadata 5 | /CSimpleRead 6 | /CSimpleWrite 7 | -------------------------------------------------------------------------------- /CMake/CMakeTestCompileSteadyClock.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using std::chrono::steady_clock; 4 | 5 | void foo(const steady_clock &clock) { 6 | return; 7 | } 8 | -------------------------------------------------------------------------------- /test/function/TapeSort/src/dbtproj.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * User: Houliang Qi 3 | * Date: 4/15/18 4 | * Time: 12:07 PM 5 | */ 6 | 7 | #include "dbtproj.h" 8 | 9 | int64_t dbtproj::totalReadTime; -------------------------------------------------------------------------------- /test/data/datagen.sh: -------------------------------------------------------------------------------- 1 | 1.download the TPC-DS from http://www.tpc.org/tpcds 2 | 3 | 2.unzip the file, cd tools 4 | 5 | 3.make 6 | 7 | 4./dsdgen -scale 5 -force, -scale means generate how much data file 8 | -------------------------------------------------------------------------------- /config.properties: -------------------------------------------------------------------------------- 1 | oss.type=QS/S3/TXCOS/OSS 2 | oss.bucket= 3 | #qingstor 4 | fs.qingstor.accessKeyId= 5 | fs.qingstor.secretAccessKey= 6 | fs.qingstor.zone=pek3a -------------------------------------------------------------------------------- /test/function/TapeSort/README.md: -------------------------------------------------------------------------------- 1 | Tape Sort 2 | =================== 3 | 4 | This project contains the source code of the TapeSort. 5 | 6 | The main.cpp is the program entrance 7 | 8 | The dbtproj.h contains the configuration of the project -------------------------------------------------------------------------------- /CMake/CMakeTestCompileNestedException.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | try { 6 | throw 2; 7 | } catch (int) { 8 | std::throw_with_nested(std::runtime_error("test")); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /mock/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | CMAKE_MINIMUM_REQUIRED(VERSION 2.8) 2 | 3 | AUTO_SOURCES(files "*.cpp" "RECURSE" "${CMAKE_CURRENT_SOURCE_DIR}") 4 | LIST(APPEND libgopherwood_MOCK_SOURCES ${files}) 5 | 6 | SET(libgopherwood_MOCK_SOURCES ${libgopherwood_MOCK_SOURCES} PARENT_SCOPE) 7 | 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .settings/ 2 | .cproject 3 | .project 4 | .idea/ 5 | build*/ 6 | releng/ 7 | ext/ 8 | dist/ 9 | obj-x86_64-linux-gnu/ 10 | test/data/unittest.xml 11 | test/data/functiontest.xml 12 | test/data/securetest.xml 13 | /cmake-build-debug/ 14 | /eric.sh 15 | /.project.bak 16 | -------------------------------------------------------------------------------- /src/libgopherwood.pc: -------------------------------------------------------------------------------- 1 | prefix=/usr/local 2 | exec_prefix=${prefix} 3 | libdir=${prefix}/lib 4 | includedir=${prefix}/include 5 | 6 | Name: libgopherwood 7 | Description: Infinite Space Buffer Support 8 | Version: 0.0.1 9 | Libs: -L${libdir} -lgopherwood 10 | Cflags: -I${includedir} 11 | -------------------------------------------------------------------------------- /CMake/CMakeTestCompileStrerror.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | // We can't test "char *p = strerror_r()" because that only causes a 6 | // compiler warning when strerror_r returns an integer. 7 | char *buf = 0; 8 | int i = strerror_r(0, buf, 100); 9 | return i; 10 | } 11 | -------------------------------------------------------------------------------- /src/libgopherwood.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@CMAKE_INSTALL_PREFIX@ 2 | exec_prefix=${prefix} 3 | libdir=${prefix}/lib 4 | includedir=${prefix}/include 5 | 6 | Name: libgopherwood 7 | Description: Infinite Space Buffer Support 8 | Version: @libgopherwood_VERSION_STRING@ 9 | Libs: -L${libdir} -lgopherwood 10 | Cflags: -I${includedir} 11 | -------------------------------------------------------------------------------- /test/function/HashJoin/README.md: -------------------------------------------------------------------------------- 1 | Hash Join 2 | =================== 3 | 4 | This project contains the source code of the TapeSort. 5 | 6 | The main.cpp is the program entrance 7 | 8 | The dbtproj.h contains the configuration of the project 9 | 10 | The test data: use the TPC-DS's data, use the item table and the catalog sales table 11 | -------------------------------------------------------------------------------- /test/function/HashJoin/src/dbtproj.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * User: Houliang Qi 3 | * Date: 3/24/18 4 | * Time: 11:12 PM 5 | */ 6 | 7 | #include "dbtproj.h" 8 | 9 | gopherwoodFS dbtproj::gwFS; 10 | int64_t dbtproj::totalReadTime; 11 | 12 | void dbtproj::formatGopherwood() { 13 | char workDir[] = WORK_DIR; 14 | gwFormatContext(workDir); 15 | 16 | } -------------------------------------------------------------------------------- /vagrant/.vagrant/machines/default/virtualbox/synced_folders: -------------------------------------------------------------------------------- 1 | {"rsync":{"/vagrant":{"type":"rsync","guestpath":"/vagrant","hostpath":"/home/qhl/cmakeworkspace/Gopherwood/vagrant","disabled":false,"__vagrantfile":true,"owner":"vagrant","group":"vagrant"}},"virtualbox":{"/gopherwood":{"owner":555,"group":555,"guestpath":"/gopherwood","hostpath":"/home/qhl/cmakeworkspace/Gopherwood","disabled":false,"__vagrantfile":true}}} -------------------------------------------------------------------------------- /vagrant/id_rsa.pub: -------------------------------------------------------------------------------- 1 | ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDGNq5e8SX5zY+ht7S3yTSC7USSzs2vbjZX2l57wysIqFRm22DUTIX03NGz9t+HRWqJQZ2P6cv2EIk5JXmhvOKbVbXfLyRHFQu8pVGT64QK4Lqt/94k5T9vong5V6xECQam/H+urN3FHTnfb2z+sEjFGcuF7BIqGBYgFV57rATG32w03ACG9GQ92Fed30ztdh94TqHtpiurWoRUHsjfLwX0oolUA4c7hSm7u+qy13XNVVznB0nXPFFRQLSiJjgo6v419S652D7W4CoslGYCk7OR2fitakk1w2zahib/kPvhWbl0+hybvfMyza5pLnYKd88QfSYBaoR+VNyOqcDBGlo3 Lirong@Lirongs-MacBook-Pro.local 2 | -------------------------------------------------------------------------------- /test/function/HashJoin/src/HashJoin.h: -------------------------------------------------------------------------------- 1 | /** 2 | * User: Houliang Qi 3 | * Date: 3/24/18 4 | * Time: 11:24 PM 5 | */ 6 | 7 | #ifndef DBMS_IMPLEMENTATION_HASHJOIN_H 8 | #define DBMS_IMPLEMENTATION_HASHJOIN_H 9 | 10 | 11 | #include "dbtproj.h" 12 | 13 | void 14 | HashJoin(char *infile1, char *infile2, unsigned char field, block_t *buffer, unsigned int nmem_blocks, char *outfile, 15 | unsigned int *nres, unsigned int *nios); 16 | 17 | 18 | #endif //DBMS_IMPLEMENTATION_HASHJOIN_H -------------------------------------------------------------------------------- /test/function/HashJoin/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | project(DBMS_Implementation) 3 | 4 | #set(CMAKE_CXX_STANDARD 11) 5 | 6 | set(SOURCE_FILES 7 | src/bufferOps.h 8 | src/dbtproj.h 9 | src/fileOps.cpp 10 | src/fileOps.h 11 | src/HashJoin.cpp 12 | src/main.cpp 13 | src/recordOps.cpp 14 | src/recordOps.h 15 | src/recordPtr.cpp 16 | src/recordPtr.h 17 | src/gopherwood.h 18 | src/dbtproj.cpp src/HashJoin.h) 19 | 20 | add_executable(DBMS_Implementation ${SOURCE_FILES}) 21 | target_link_libraries(DBMS_Implementation gopherwood) -------------------------------------------------------------------------------- /test/function/TapeSort/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | project(DBMS_Implementation) 3 | 4 | #set(CMAKE_CXX_STANDARD 11) 5 | 6 | set(SOURCE_FILES 7 | src/bufferOps.h 8 | src/dbtproj.h 9 | src/fileOps.cpp 10 | src/fileOps.h 11 | src/main.cpp 12 | src/MergeSort.cpp 13 | src/recordOps.cpp 14 | src/recordOps.h 15 | src/recordPtr.cpp 16 | src/recordPtr.h 17 | src/sortBuffer.cpp 18 | src/gopherwood.h 19 | src/sortBuffer.h src/dbtproj.cpp) 20 | 21 | add_executable(DBMS_Implementation ${SOURCE_FILES}) 22 | target_link_libraries(DBMS_Implementation gopherwood) -------------------------------------------------------------------------------- /CMake/FindLiboss.cmake: -------------------------------------------------------------------------------- 1 | # - Find OSS 2 | # Find the native OSS includes and library 3 | # 4 | # OSS_INCLUDE_DIR - where to find oss/oss.h, etc. 5 | # OSS_LIBRARIES - List of libraries when using liboss. 6 | # OSS_FOUND - True if OSS found. 7 | 8 | IF (OSS_INCLUDE_DIR AND OSS_LIBRARIES) 9 | # Already in cache, be silent 10 | SET(OSS_FIND_QUIETLY TRUE) 11 | ENDIF (OSS_INCLUDE_DIR AND OSS_LIBRARIES) 12 | 13 | FIND_PATH(OSS_INCLUDE_DIR oss/oss.h) 14 | 15 | SET(OSS_NAMES oss) 16 | FIND_LIBRARY(OSS_LIBRARIES NAMES ${OSS_NAMES}) 17 | 18 | # handle the QUIETLY and REQUIRED arguments and set OSS_FOUND to TRUE if 19 | # all listed variables are TRUE 20 | INCLUDE(FindPackageHandleStandardArgs) 21 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(oss DEFAULT_MSG OSS_LIBRARIES OSS_INCLUDE_DIR) 22 | 23 | MARK_AS_ADVANCED(OSS_LIBRARIES OSS_INCLUDE_DIR) 24 | -------------------------------------------------------------------------------- /vagrant/vagrant-setup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -x -e 4 | 5 | # install packages needed to build and run GPDB 6 | curl -L https://pek3a.qingstor.com/hashdata-public/tools/centos7/libarchive/libarchive.repo -o /etc/yum.repos.d/libarchive.repo 7 | sudo yum -y update 8 | sudo yum -y groupinstall "Development Tools" 9 | sudo yum -y install epel-release 10 | sudo yum -y install \ 11 | vim \ 12 | doxygen \ 13 | cmake \ 14 | which \ 15 | make \ 16 | rpmdevtools \ 17 | gcc-c++ \ 18 | boost-devel \ 19 | cyrus-sasl-devel \ 20 | cyrus-sasl-plain \ 21 | cyrus-sasl-gssapi \ 22 | libevent-devel \ 23 | zlib-devel \ 24 | openssl-devel \ 25 | wget \ 26 | git \ 27 | java-1.8.0-openjdk \ 28 | ed \ 29 | which \ 30 | go \ 31 | json-c-devel \ 32 | curl-devel \ 33 | libyaml-devel \ 34 | protobuf \ 35 | lcov \ 36 | 37 | #add liboss dependency 38 | 39 | -------------------------------------------------------------------------------- /vagrant/vagrant-ssh.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -x 4 | 5 | # Create hashdata user 6 | #sudo groupadd -g 555 hashdata 7 | #sudo useradd -u 555 -g 555 hashdata 8 | sudo groupadd -g 555 hashdata 9 | sudo useradd -u 555 -g 555 hashdata 10 | sudo echo "%hashdata ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/hashdata 11 | 12 | SSH_DIR=/home/hashdata/.ssh 13 | AUTH_FILE="$SSH_DIR"/authorized_keys 14 | PRIVATE_KEY_FILE="$SSH_DIR"/id_rsa 15 | 16 | sudo rm -rf "$SSH_DIR" 17 | 18 | sudo mkdir "$SSH_DIR" 19 | sudo chmod 0700 "$SSH_DIR" 20 | sudo cat /vagrant/id_rsa.pub > "$AUTH_FILE" 21 | sudo cat /vagrant/id_rsa > "$PRIVATE_KEY_FILE" 22 | sudo chmod 0600 "$AUTH_FILE" 23 | sudo chmod 0600 "$PRIVATE_KEY_FILE" 24 | sudo chown -R hashdata "$SSH_DIR" 25 | sudo chgrp -R hashdata "$SSH_DIR" 26 | 27 | sudo echo "export JAVA_HOME=/etc/alternatives/jre" >> /home/hashdata/.bash_profile 28 | -------------------------------------------------------------------------------- /src/platform.h.in: -------------------------------------------------------------------------------- 1 | #define THREAD_LOCAL __thread 2 | #define ATTRIBUTE_NORETURN __attribute__ ((noreturn)) 3 | #define ATTRIBUTE_NOINLINE __attribute__ ((noinline)) 4 | 5 | #define GCC_VERSION (__GNUC__ * 10000 \ 6 | + __GNUC_MINOR__ * 100 \ 7 | + __GNUC_PATCHLEVEL__) 8 | 9 | #cmakedefine LIBUNWIND_FOUND 10 | #cmakedefine HAVE_DLADDR 11 | #cmakedefine OS_LINUX 12 | #cmakedefine OS_MACOSX 13 | #cmakedefine ENABLE_FRAME_POINTER 14 | #cmakedefine HAVE_SYMBOLIZE 15 | #cmakedefine NEED_BOOST 16 | #cmakedefine STRERROR_R_RETURN_INT 17 | #cmakedefine HAVE_STEADY_CLOCK 18 | #cmakedefine HAVE_NESTED_EXCEPTION 19 | #cmakedefine HAVE_BOOST_CHRONO 20 | #cmakedefine HAVE_STD_CHRONO 21 | #cmakedefine HAVE_BOOST_ATOMIC 22 | #cmakedefine HAVE_STD_ATOMIC 23 | 24 | // defined by gcc 25 | #if defined(__ELF__) && defined(OS_LINUX) 26 | # define HAVE_SYMBOLIZE 27 | #elif defined(OS_MACOSX) && defined(HAVE_DLADDR) 28 | // Use dladdr to symbolize. 29 | # define HAVE_SYMBOLIZE 30 | #endif 31 | 32 | #define STACK_LENGTH 64 33 | -------------------------------------------------------------------------------- /test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | CMAKE_MINIMUM_REQUIRED(VERSION 2.8) 2 | 3 | SET(GCC_LRT_LINK_FLAGS "-lrt") 4 | SET(GCC_MD5_LINK_FLAGS "-lcrypto") 5 | SET(TEST_WORKING_DIR ${CMAKE_CURRENT_SOURCE_DIR}/data/) 6 | SET( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GCC_LRT_LINK_FLAGS} ${GCC_MD5_LINK_FLAGS}" ) 7 | 8 | ADD_DEFINITIONS(-DGTEST_LANG_CXX11=0 -Dprivate=public -Dprotected=public -DDATA_DIR="${TEST_WORKING_DIR}/") 9 | 10 | 11 | ADD_SUBDIRECTORY(function) 12 | 13 | IF(TEST_RUNNER) 14 | SEPARATE_ARGUMENTS(TEST_RUNNER_LIST UNIX_COMMAND ${TEST_RUNNER}) 15 | ENDIF(TEST_RUNNER) 16 | 17 | ADD_CUSTOM_TARGET(functiontest 18 | COMMAND ${TEST_RUNNER_LIST} ${CMAKE_CURRENT_BINARY_DIR}/function/function 19 | DEPENDS function 20 | WORKING_DIRECTORY ${TEST_WORKING_DIR} 21 | COMMENT "Run Function Test..." 22 | ) 23 | 24 | ADD_CUSTOM_TARGET(testAll 25 | COMMAND ${CMAKE_MAKE_PROGRAM} functiontest || true 26 | COMMENT "Run All Test..." 27 | ) 28 | 29 | SET(function_SOURCES ${function_SOURCES} PARENT_SCOPE) 30 | 31 | # the following is added by qihouliang 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /test/function/TapeSort/src/sortBuffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * DBMS Implementation 3 | * Copyright (C) 2013 George Piskas, George Economides 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | * 19 | * Contact: geopiskas@gmail.com 20 | */ 21 | 22 | #ifndef SORTBUFFER_H 23 | #define SORTBUFFER_H 24 | 25 | #include 26 | 27 | #include "dbtproj.h" 28 | 29 | // sorts the records in the buffer 30 | bool sortBuffer(block_t* buffer, uint bufferSize, unsigned char field); 31 | 32 | #endif 33 | 34 | -------------------------------------------------------------------------------- /gtest/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | CMAKE_MINIMUM_REQUIRED(VERSION 2.8) 2 | 3 | #SET(gtest_VERSION_MAJOR 1) 4 | #SET(gtest_VERSION_MINOR 1) 5 | #SET(gtest_API_VERSION ${gtest_VERSION_MAJOR}) 6 | 7 | SET(gtest_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/gtest ${CMAKE_SOURCE_DIR}/gtest/include) 8 | SET(gtest_SOURCES_DIR ${CMAKE_SOURCE_DIR}/gtest) 9 | 10 | AUTO_SOURCES(files "*.cc" "RECURSE" "${CMAKE_CURRENT_SOURCE_DIR}") 11 | LIST(APPEND gtest_SOURCES ${files}) 12 | 13 | AUTO_SOURCES(files "*.h" "RECURSE" "${CMAKE_CURRENT_SOURCE_DIR}") 14 | LIST(APPEND gtest_SOURCES ${files}) 15 | 16 | #ADD_LIBRARY(gtest-static STATIC ${gtest_SOURCES}) 17 | #ADD_LIBRARY(gtest-shared SHARED ${gtest_SOURCES}) 18 | 19 | #INCLUDE_DIRECTORIES(${gtest_INCLUDE_DIR} ${gtest_SOURCES_DIR}) 20 | 21 | #SET_TARGET_PROPERTIES(gtest-static PROPERTIES OUTPUT_NAME "gtest") 22 | #SET_TARGET_PROPERTIES(gtest-shared PROPERTIES OUTPUT_NAME "gtest") 23 | 24 | SET(gtest_SOURCES ${gtest_SOURCES} PARENT_SCOPE) 25 | SET(gtest_INCLUDE_DIR ${gtest_INCLUDE_DIR} PARENT_SCOPE) 26 | SET(gtest_SOURCES_DIR ${gtest_SOURCES_DIR} PARENT_SCOPE) 27 | 28 | #SET_TARGET_PROPERTIES(gtest-shared PROPERTIES VERSION ${gtest_VERSION_MAJOR}.${gtest_VERSION_MINOR} SOVERSION ${gtest_API_VERSION}) -------------------------------------------------------------------------------- /gmock/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | CMAKE_MINIMUM_REQUIRED(VERSION 2.8) 2 | 3 | #SET(gmock_VERSION_MAJOR 1) 4 | #SET(gmock_VERSION_MINOR 1) 5 | #SET(gmock_API_VERSION ${gmock_VERSION_MAJOR}) 6 | 7 | SET(gmock_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/gmock/include) 8 | SET(gmock_SOURCES_DIR ${CMAKE_SOURCE_DIR}/gmock) 9 | 10 | AUTO_SOURCES(files "*.cc" "RECURSE" "${CMAKE_CURRENT_SOURCE_DIR}") 11 | LIST(APPEND gmock_SOURCES ${files}) 12 | 13 | AUTO_SOURCES(files "*.h" "RECURSE" "${CMAKE_CURRENT_SOURCE_DIR}") 14 | LIST(APPEND gmock_SOURCES ${files}) 15 | 16 | #ADD_LIBRARY(gmock-static STATIC ${gmock_SOURCES}) 17 | #ADD_LIBRARY(gmock-shared SHARED ${gmock_SOURCES}) 18 | 19 | #INCLUDE_DIRECTORIES(${gmock_INCLUDE_DIR} ${gmock_SOURCES_DIR} ${gtest_INCLUDE_DIR} ${gtest_SOURCES_DIR}) 20 | 21 | #TARGET_LINK_LIBRARIES(gmock-static gtest) 22 | #TARGET_LINK_LIBRARIES(gmock-shared gtest) 23 | 24 | #SET_TARGET_PROPERTIES(gmock-static PROPERTIES OUTPUT_NAME "gmock") 25 | #SET_TARGET_PROPERTIES(gmock-shared PROPERTIES OUTPUT_NAME "gmock") 26 | 27 | SET(gmock_SOURCES ${gmock_SOURCES} PARENT_SCOPE) 28 | SET(gmock_INCLUDE_DIR ${gmock_INCLUDE_DIR} PARENT_SCOPE) 29 | SET(gmock_SOURCES_DIR ${gmock_SOURCES_DIR} PARENT_SCOPE) 30 | 31 | #SET_TARGET_PROPERTIES(gmock-shared PROPERTIES VERSION ${gmock_VERSION_MAJOR}.${gmock_VERSION_MINOR} SOVERSION ${gmock_API_VERSION}) -------------------------------------------------------------------------------- /test/function/FunctionTestMain.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * 2016 - 3 | * open source under Apache License Version 2.0 4 | ********************************************************************/ 5 | /** 6 | * Licensed to the Apache Software Foundation (ASF) under one 7 | * or more contributor license agreements. See the NOTICE file 8 | * distributed with this work for additional information 9 | * regarding copyright ownership. The ASF licenses this file 10 | * to you under the Apache License, Version 2.0 (the 11 | * "License"); you may not use this file except in compliance 12 | * with the License. You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | #include "gtest/gtest.h" 23 | 24 | int main(int argc, char ** argv) { 25 | ::testing::InitGoogleTest(&argc, argv); 26 | #ifdef DATA_DIR 27 | if (0 != chdir(DATA_DIR)) { 28 | abort(); 29 | } 30 | #endif 31 | return RUN_ALL_TESTS(); 32 | } 33 | -------------------------------------------------------------------------------- /CMake/Functions.cmake: -------------------------------------------------------------------------------- 1 | FUNCTION(AUTO_SOURCES RETURN_VALUE PATTERN SOURCE_SUBDIRS) 2 | 3 | IF ("${SOURCE_SUBDIRS}" STREQUAL "RECURSE") 4 | SET(PATH ".") 5 | IF (${ARGC} EQUAL 4) 6 | LIST(GET ARGV 3 PATH) 7 | ENDIF () 8 | ENDIF() 9 | 10 | IF ("${SOURCE_SUBDIRS}" STREQUAL "RECURSE") 11 | UNSET(${RETURN_VALUE}) 12 | FILE(GLOB SUBDIR_FILES "${PATH}/${PATTERN}") 13 | LIST(APPEND ${RETURN_VALUE} ${SUBDIR_FILES}) 14 | 15 | FILE(GLOB SUBDIRS RELATIVE ${PATH} ${PATH}/*) 16 | 17 | FOREACH(DIR ${SUBDIRS}) 18 | IF (IS_DIRECTORY ${PATH}/${DIR}) 19 | IF (NOT "${DIR}" STREQUAL "CMAKEFILES") 20 | FILE(GLOB_RECURSE SUBDIR_FILES "${PATH}/${DIR}/${PATTERN}") 21 | LIST(APPEND ${RETURN_VALUE} ${SUBDIR_FILES}) 22 | ENDIF() 23 | ENDIF() 24 | ENDFOREACH() 25 | ELSE () 26 | FILE(GLOB ${RETURN_VALUE} "${PATTERN}") 27 | 28 | FOREACH (PATH ${SOURCE_SUBDIRS}) 29 | FILE(GLOB SUBDIR_FILES "${PATH}/${PATTERN}") 30 | LIST(APPEND ${RETURN_VALUE} ${SUBDIR_FILES}) 31 | ENDFOREACH(PATH ${SOURCE_SUBDIRS}) 32 | ENDIF () 33 | 34 | IF (${FILTER_OUT}) 35 | LIST(REMOVE_ITEM ${RETURN_VALUE} ${FILTER_OUT}) 36 | ENDIF() 37 | 38 | SET(${RETURN_VALUE} ${${RETURN_VALUE}} PARENT_SCOPE) 39 | ENDFUNCTION(AUTO_SOURCES) 40 | 41 | FUNCTION(CONTAINS_STRING FILE SEARCH RETURN_VALUE) 42 | FILE(STRINGS ${FILE} FILE_CONTENTS REGEX ".*${SEARCH}.*") 43 | IF (FILE_CONTENTS) 44 | SET(${RETURN_VALUE} TRUE PARENT_SCOPE) 45 | ENDIF() 46 | ENDFUNCTION(CONTAINS_STRING) 47 | -------------------------------------------------------------------------------- /src/common/Exception.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * 2017 - 3 | * open source under Apache License Version 2.0 4 | ********************************************************************/ 5 | /** 6 | * Licensed to the Apache Software Foundation (ASF) under one 7 | * or more contributor license agreements. See the NOTICE file 8 | * distributed with this work for additional information 9 | * regarding copyright ownership. The ASF licenses this file 10 | * to you under the Apache License, Version 2.0 (the 11 | * "License"); you may not use this file except in compliance 12 | * with the License. You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | #include "Exception.h" 23 | #include "ExceptionInternal.h" 24 | 25 | #include 26 | 27 | namespace Gopherwood { 28 | 29 | GopherwoodException::GopherwoodException(const std::string &arg, const char *file, int line, 30 | const char *stack) : 31 | std::runtime_error(arg) { 32 | std::ostringstream ss; 33 | ss << file << ": " << line << ": " << arg << std::endl << stack; 34 | detail = ss.str(); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/common/StackPrinter.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * 2017 - 3 | * open source under Apache License Version 2.0 4 | ********************************************************************/ 5 | /** 6 | * Licensed to the Apache Software Foundation (ASF) under one 7 | * or more contributor license agreements. See the NOTICE file 8 | * distributed with this work for additional information 9 | * regarding copyright ownership. The ASF licenses this file 10 | * to you under the Apache License, Version 2.0 (the 11 | * "License"); you may not use this file except in compliance 12 | * with the License. You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | #ifndef _GOPHERWOOD_COMMON_STACK_PRINTER_H_ 23 | #define _GOPHERWOOD_COMMON_STACK_PRINTER_H_ 24 | 25 | #include "platform.h" 26 | 27 | #include 28 | 29 | #ifndef DEFAULT_STACK_PREFIX 30 | #define DEFAULT_STACK_PREFIX "\t@\t" 31 | #endif 32 | 33 | namespace Gopherwood { 34 | namespace Internal { 35 | 36 | extern const std::string PrintStack(int skip, int maxDepth); 37 | 38 | } 39 | } 40 | 41 | #endif /* _GOPHERWOOD_COMMON_STACK_PRINTER_H_ */ 42 | -------------------------------------------------------------------------------- /test/function/HashJoin/src/recordOps.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * DBMS Implementation 3 | * Copyright (C) 2013 George Piskas, George Economides 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | * 19 | * Contact: geopiskas@gmail.com 20 | */ 21 | 22 | #include "recordOps.h" 23 | 24 | #include 25 | 26 | // frees the memory allocated to a hash index 27 | 28 | void destroyHashIndex(linkedRecordPtr **hashIndex, uint size) { 29 | for (uint i = 0; i < size; i++) { 30 | if (!hashIndex[i]) { 31 | continue; 32 | } 33 | linkedRecordPtr *temp1 = hashIndex[i]; 34 | linkedRecordPtr *temp2 = temp1->next; 35 | while (temp1) { 36 | free(temp1); 37 | temp1 = temp2; 38 | if (temp2) { 39 | temp2 = temp2->next; 40 | } 41 | } 42 | } 43 | free(hashIndex); 44 | } 45 | -------------------------------------------------------------------------------- /test/function/TapeSort/src/recordOps.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * DBMS Implementation 3 | * Copyright (C) 2013 George Piskas, George Economides 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | * 19 | * Contact: geopiskas@gmail.com 20 | */ 21 | 22 | #include "recordOps.h" 23 | 24 | #include 25 | 26 | // frees the memory allocated to a hash index 27 | 28 | void destroyHashIndex(linkedRecordPtr **hashIndex, uint size) { 29 | for (uint i = 0; i < size; i++) { 30 | if (!hashIndex[i]) { 31 | continue; 32 | } 33 | linkedRecordPtr *temp1 = hashIndex[i]; 34 | linkedRecordPtr *temp2 = temp1->next; 35 | while (temp1) { 36 | free(temp1); 37 | temp1 = temp2; 38 | if (temp2) { 39 | temp2 = temp2->next; 40 | } 41 | } 42 | } 43 | free(hashIndex); 44 | } 45 | -------------------------------------------------------------------------------- /gmock/COPYING: -------------------------------------------------------------------------------- 1 | Copyright 2008, Google Inc. 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are 6 | met: 7 | 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above 11 | copyright notice, this list of conditions and the following disclaimer 12 | in the documentation and/or other materials provided with the 13 | distribution. 14 | * Neither the name of Google Inc. nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | -------------------------------------------------------------------------------- /test/function/TapeSort/src/fileOps.h: -------------------------------------------------------------------------------- 1 | /* 2 | * DBMS Implementation 3 | * Copyright (C) 2013 George Piskas, George Economides 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | * 19 | * Contact: geopiskas@gmail.com 20 | */ 21 | 22 | #ifndef FILEOPS_H 23 | #define FILEOPS_H 24 | 25 | #include 26 | #include 27 | 28 | #include "dbtproj.h" 29 | #include "gopherwood.h" 30 | 31 | 32 | void formatGopherwood(); 33 | 34 | gopherwoodFS initContext(); 35 | 36 | void printFileInfo(GWFileInfo *fileInfo); 37 | 38 | void createFromTpcds(char *filename, uint size); 39 | 40 | void createFile(char *filename, uint size); 41 | 42 | void printFile(char *filename); 43 | 44 | // returns the size of a file 45 | 46 | int getSize(char *filename); 47 | 48 | // returns true if file exists, false otherwise 49 | 50 | int exists(char *filename); 51 | 52 | #endif 53 | 54 | -------------------------------------------------------------------------------- /test/function/HashJoin/src/fileOps.h: -------------------------------------------------------------------------------- 1 | /* 2 | * DBMS Implementation 3 | * Copyright (C) 2013 George Piskas, George Economides 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | * 19 | * Contact: geopiskas@gmail.com 20 | */ 21 | 22 | #ifndef FILEOPS_H 23 | #define FILEOPS_H 24 | 25 | #include 26 | #include 27 | 28 | #include "dbtproj.h" 29 | #include "gopherwood.h" 30 | 31 | class fileOps { 32 | public: 33 | fileOps() { 34 | 35 | } 36 | 37 | ~fileOps() { 38 | 39 | } 40 | 41 | 42 | void printFileInfo(GWFileInfo *fileInfo); 43 | 44 | void createTwoFiles(char *filename1, uint size1, char *filename2, uint size2); 45 | 46 | // returns the size of a file 47 | 48 | int getSize(char *filename); 49 | 50 | // returns true if file exists, false otherwise 51 | 52 | int exists(char *filename); 53 | 54 | void printFile(char *filename); 55 | 56 | }; 57 | 58 | #endif 59 | 60 | -------------------------------------------------------------------------------- /src/block/LocalBlockReader.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * 2017 - 3 | * open source under Apache License Version 2.0 4 | ********************************************************************/ 5 | /** 6 | * Licensed to the Apache Software Foundation (ASF) under one 7 | * or more contributor license agreements. See the NOTICE file 8 | * distributed with this work for additional information 9 | * regarding copyright ownership. The ASF licenses this file 10 | * to you under the Apache License, Version 2.0 (the 11 | * "License"); you may not use this file except in compliance 12 | * with the License. You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | #ifndef GOPHERWOOD_BLOCK_LOCALBLOCKREADER_H 23 | #define GOPHERWOOD_BLOCK_LOCALBLOCKREADER_H 24 | 25 | #include "platform.h" 26 | 27 | #include "common/Memory.h" 28 | 29 | namespace Gopherwood { 30 | namespace Internal { 31 | 32 | class LocalBlockReader { 33 | public: 34 | LocalBlockReader(int fd); 35 | 36 | int seek(int64_t offset); 37 | 38 | int readLocal(char *buffer, int64_t length); 39 | 40 | ~LocalBlockReader(); 41 | 42 | private: 43 | int mLocalSpaceFD; 44 | }; 45 | 46 | } 47 | } 48 | #endif //GOPHERWOOD_BLOCK_LOCALBLOCKREADER_H 49 | -------------------------------------------------------------------------------- /src/block/LocalBlockReader.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * 2017 - 3 | * open source under Apache License Version 2.0 4 | ********************************************************************/ 5 | /** 6 | * Licensed to the Apache Software Foundation (ASF) under one 7 | * or more contributor license agreements. See the NOTICE file 8 | * distributed with this work for additional information 9 | * regarding copyright ownership. The ASF licenses this file 10 | * to you under the Apache License, Version 2.0 (the 11 | * "License"); you may not use this file except in compliance 12 | * with the License. You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | #include "block/LocalBlockReader.h" 23 | #include "common/Logger.h" 24 | 25 | namespace Gopherwood { 26 | namespace Internal { 27 | 28 | LocalBlockReader::LocalBlockReader(int fd) : mLocalSpaceFD(fd) { 29 | } 30 | 31 | int LocalBlockReader::seek(int64_t offset) { 32 | int64_t res = lseek(mLocalSpaceFD, offset, SEEK_SET); 33 | return res; 34 | } 35 | 36 | int LocalBlockReader::readLocal(char *buffer, int64_t length) { 37 | int64_t res = read(mLocalSpaceFD, buffer, length); 38 | return res; 39 | } 40 | 41 | LocalBlockReader::~LocalBlockReader() { 42 | 43 | } 44 | 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/common/Thread.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * 2017 - 3 | * open source under Apache License Version 2.0 4 | ********************************************************************/ 5 | /** 6 | * Licensed to the Apache Software Foundation (ASF) under one 7 | * or more contributor license agreements. See the NOTICE file 8 | * distributed with this work for additional information 9 | * regarding copyright ownership. The ASF licenses this file 10 | * to you under the Apache License, Version 2.0 (the 11 | * "License"); you may not use this file except in compliance 12 | * with the License. You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | 23 | #include 24 | 25 | #include "Thread.h" 26 | 27 | namespace Gopherwood { 28 | namespace Internal { 29 | 30 | sigset_t ThreadBlockSignal() { 31 | sigset_t sigs; 32 | sigset_t oldMask; 33 | sigemptyset(&sigs); 34 | sigaddset(&sigs, SIGHUP); 35 | sigaddset(&sigs, SIGINT); 36 | sigaddset(&sigs, SIGTERM); 37 | sigaddset(&sigs, SIGUSR1); 38 | sigaddset(&sigs, SIGUSR2); 39 | pthread_sigmask(SIG_BLOCK, &sigs, &oldMask); 40 | return oldMask; 41 | } 42 | 43 | void ThreadUnBlockSignal(sigset_t sigs) { 44 | pthread_sigmask(SIG_SETMASK, &sigs, 0); 45 | } 46 | 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/common/Memory.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * 2017 - 3 | * open source under Apache License Version 2.0 4 | ********************************************************************/ 5 | /** 6 | * Licensed to the Apache Software Foundation (ASF) under one 7 | * or more contributor license agreements. See the NOTICE file 8 | * distributed with this work for additional information 9 | * regarding copyright ownership. The ASF licenses this file 10 | * to you under the Apache License, Version 2.0 (the 11 | * "License"); you may not use this file except in compliance 12 | * with the License. You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | #ifndef _GOPHERWOOD_COMMON_MEMORY_H_ 23 | #define _GOPHERWOOD_COMMON_MEMORY_H_ 24 | 25 | #include "platform.h" 26 | 27 | #ifdef NEED_BOOST 28 | 29 | #include 30 | #include 31 | 32 | namespace Gopherwood { 33 | namespace Internal { 34 | 35 | using boost::shared_ptr; 36 | using boost::make_shared; 37 | 38 | } 39 | } 40 | 41 | #else 42 | 43 | #include 44 | 45 | namespace Gopherwood { 46 | namespace Internal { 47 | 48 | using std::shared_ptr; 49 | using std::make_shared; 50 | 51 | } 52 | } 53 | #endif 54 | 55 | #endif /* _GOPHERWOOD_COMMON_MEMORY_H_ */ 56 | -------------------------------------------------------------------------------- /src/common/Function.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * 2017 - 3 | * open source under Apache License Version 2.0 4 | ********************************************************************/ 5 | /** 6 | * Licensed to the Apache Software Foundation (ASF) under one 7 | * or more contributor license agreements. See the NOTICE file 8 | * distributed with this work for additional information 9 | * regarding copyright ownership. The ASF licenses this file 10 | * to you under the Apache License, Version 2.0 (the 11 | * "License"); you may not use this file except in compliance 12 | * with the License. You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | #ifndef _GOPHERWOOD_COMMON_FUNCTION_H_ 23 | #define _GOPHERWOOD_COMMON_FUNCTION_H_ 24 | 25 | #include "platform.h" 26 | 27 | #ifdef NEED_BOOST 28 | #include 29 | #include 30 | 31 | namespace Gopherwood { 32 | 33 | using boost::function; 34 | using boost::bind; 35 | using boost::reference_wrapper; 36 | 37 | } 38 | 39 | #else 40 | 41 | #include 42 | 43 | namespace Gopherwood { 44 | 45 | using std::function; 46 | using std::bind; 47 | using std::reference_wrapper; 48 | using namespace std::placeholders; 49 | 50 | } 51 | 52 | #endif 53 | 54 | #endif /* _GOPHERWOOD_COMMON_FUNCTION_H_ */ 55 | -------------------------------------------------------------------------------- /vagrant/id_rsa: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIIEogIBAAKCAQEAxjauXvEl+c2Pobe0t8k0gu1Eks7Nr242V9pee8MrCKhUZttg 3 | 1EyF9NzRs/bfh0VqiUGdj+nL9hCJOSV5obzim1W13y8kRxULvKVRk+uECuC6rf/e 4 | JOU/b6J4OVesRAkGpvx/rqzdxR05329s/rBIxRnLhewSKhgWIBVee6wExt9sNNwA 5 | hvRkPdhXnd9M7XYfeE6h7aYrq1qEVB7I3y8F9KKJVAOHO4Upu7vqstd1zVVc5wdJ 6 | 1zxRUUC0oiY4KOr+NfUuudg+1uAqLJRmApOzkdn4rWpJNcNs2oYm/5D74Vm5dPoc 7 | m73zMs2uaS52CnfPEH0mAWqEflTcjqnAwRpaNwIDAQABAoIBAEpp5PTH29X4kl/I 8 | NBR7eTdeFEx5T0b5PXWmCaq1DsblSyqCWcvaHsBa1m+V0z1ZljGJbLnGsEfk1V+a 9 | 7hsGapyehPURIbF9+TYNap754EylKfCBCskXN8WVXUVJ4OZ57QFr8hOF2oxR+JQl 10 | pOnJDMjSclII2pjrCgNpglszrWdrd0BOkjhp01xrJ637cEwsTpfIAgUafjAHGUjj 11 | q9fwNxweRmetvvtBXD1yLRrjJqWtuzzwZD6a80IO6KXKR0j3JZLQ+krw9basJS1W 12 | tXo6JyCKeDxGEIEcUTTlezNmI868FKIzXW9Wr9Nazbc2IyfEHYHIZb7f5G6me9bq 13 | 9uVi4OECgYEA/czoU45/gdQjppXEEPA//lwr5So6ixDbiRCE5smvDLGPMl6GeQyr 14 | WScV1la0Teir8yH7FB3Zm1ZbG0kYnMsc1Lx+l2JGHsYaJR5A0nOwRTmMGwZlXKL5 15 | sS1hfZ7rgRkDUTBWlkfInlzXA1SYwZ47IymAsOU5gUbcgpsW9wh6xRUCgYEAx+5y 16 | QU/l7LYNDFUcdY11HLKFReMhAuxuUfUDlqHhigKicSijEVXtgYQ5wnvZOV1aiP98 17 | J0BILhUtfSoTgXIMcIoq6nTg51ehurVjJ4E9uxAUAcp/HDHD1zc1OZ7lFQOwD82w 18 | 42bveMYJorGoSLE/0kFnrG3/c4VEjRZBMgPvjRsCgYBEzxEN1kxrfoBL4b7OeNRg 19 | ucyMzO4iVeevOXNOvs9euaUBGu+KUg0Clr4s5kTr+nDj8gqIYa9llfwNYbvyhn7C 20 | jngjwtkP7tWXyqP4arUXj4qUqR9CBk1747nSvQtMbOOhV2GiTMPva2w/0ue3Vpbh 21 | 6ZaiXwNAMV4HatTHFN10IQKBgFGB9naF+jicp4klkaqi9uGyLf8l76lfdkJXXxUj 22 | /ezj0hHL/V7t5xvsKhgNoatvUZ+UeKsP291dqOPkKXuWYVfoHELlT2NBKKATns7W 23 | M7J1hZKNWXDHIQ42Za6OBtqgXEC1HK44otxb8EWxo+euy1QOchOr7H7OD/ps3jtj 24 | u1+NAoGAYWWptO5r8Gc8P268uwvwLg20ESyOh59LERRfnsYGKkjH55sz+83Jh8P2 25 | PRLJ1KvJddZslG7BhTW+lyIDPRypweBQOWLyn/L+KP3HtHFk3LQHDvVMHpRZmG7W 26 | 2IJzo95KeWT3+QnnaUQwi8rOd3bUpG368CaRudks8uTdm6O2qVg= 27 | -----END RSA PRIVATE KEY----- 28 | -------------------------------------------------------------------------------- /src/common/Unordered.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * 2017 - 3 | * open source under Apache License Version 2.0 4 | ********************************************************************/ 5 | /** 6 | * Licensed to the Apache Software Foundation (ASF) under one 7 | * or more contributor license agreements. See the NOTICE file 8 | * distributed with this work for additional information 9 | * regarding copyright ownership. The ASF licenses this file 10 | * to you under the Apache License, Version 2.0 (the 11 | * "License"); you may not use this file except in compliance 12 | * with the License. You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | #ifndef _GOPHERWOOD_COMMON_UNORDERED_H_ 23 | #define _GOPHERWOOD_COMMON_UNORDERED_H_ 24 | 25 | #include "platform.h" 26 | 27 | #ifdef NEED_BOOST 28 | 29 | #include 30 | #include 31 | 32 | namespace Gopherwood { 33 | namespace Internal { 34 | 35 | using boost::unordered_map; 36 | using boost::unordered_set; 37 | 38 | } 39 | } 40 | 41 | #else 42 | 43 | #include 44 | #include 45 | 46 | namespace Gopherwood { 47 | namespace Internal { 48 | 49 | using std::unordered_map; 50 | using std::unordered_set; 51 | 52 | } 53 | } 54 | #endif 55 | 56 | #endif /* _GOPHERWOOD_COMMON_UNORDERED_H_ */ 57 | -------------------------------------------------------------------------------- /src/block/LocalBlockWriter.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * 2017 - 3 | * open source under Apache License Version 2.0 4 | ********************************************************************/ 5 | /** 6 | * Licensed to the Apache Software Foundation (ASF) under one 7 | * or more contributor license agreements. See the NOTICE file 8 | * distributed with this work for additional information 9 | * regarding copyright ownership. The ASF licenses this file 10 | * to you under the Apache License, Version 2.0 (the 11 | * "License"); you may not use this file except in compliance 12 | * with the License. You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | #include "block/LocalBlockWriter.h" 23 | #include "common/Logger.h" 24 | 25 | namespace Gopherwood { 26 | namespace Internal { 27 | 28 | LocalBlockWriter::LocalBlockWriter(int fd) : mLocalSpaceFD(fd) { 29 | mOffset = 0; 30 | } 31 | 32 | int LocalBlockWriter::seek(int64_t offset) { 33 | int res = lseek(mLocalSpaceFD, offset, SEEK_SET); 34 | return res; 35 | } 36 | 37 | int LocalBlockWriter::writeLocal(const char *buffer, int64_t length) { 38 | int res = write(mLocalSpaceFD, buffer, length); 39 | return res; 40 | } 41 | 42 | void LocalBlockWriter::flush() { 43 | fsync(mLocalSpaceFD); 44 | } 45 | 46 | LocalBlockWriter::~LocalBlockWriter() { 47 | 48 | } 49 | 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /vagrant/.vagrant/machines/default/virtualbox/private_key: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIIEowIBAAKCAQEAtu++SSJmlNSBOvwaSPAz2NlsgmcK2rrl4wYKeOdt5eutabOl 3 | muOBeGeimnLLSWJE3X36hC02REtJDCunympZ/l8uNdRCMCK1TWVyF8uIsM5VIWlM 4 | iiyihnif1XWHZruIkVAnmi54dZw3EgunFdWx8a7CPmppKfydwVLH24yMkbqEiVIC 5 | ELVFW6pf1z2tTBoMhNYMMc8fejhjW+ppRQlSkiiTasVciO/8mzZliWEafWVDxLoj 6 | s4ifc8ljk7kIX6XuyfwF6aQAxRBnm0XJP/SMMY5wBrSG0C3bNLAJUqVc7IYZ1yJS 7 | 9MQLDkfFU4zrmbiqAq4cpIgG8/HA75XUW8SzVQIDAQABAoIBAQCrBS5LiNGFybSW 8 | xCB+l7CgxYLf1h0bpyZLOtaHeTQQgme4La5gQthDC//DjBXoIOpoduHAt9PHvOop 9 | apaOcSZ429qDkE/gWFJObMxg2nKLeBm2Bo77jgbS1+n00M8oh6GA2AJt7YvHx6bk 10 | Q+iMTR7x5oLJfwmZqwSAOzeEVL0Fbli/68txLW9JHJb5WoCU0rp2fwI15TTRxiqv 11 | FPrLPeKE7J17gYSNOEKeXDWDU5kcMJO7WGaru3/4sKNjFwKd9poT9+gnvtZta0af 12 | u0FqplTTuatpfqf9xWdylovFMKYAlD3tMhojrzNqsYpVyq6PsWsYMq4AOxrmSCD0 13 | SRBNx74BAoGBAN3zEutL9DsyyW4wLa2qWUXX0yO92pvniL4xx1PCpdDnYe2vM+cq 14 | 8HU0HaVMd5iowTleEIWInN4Aa49+Ri1I6hxTlO9uYPdXzPA9d+Dj69Oza8rmUs9z 15 | 3la2CJ+0xvgEHdy5pUjidDA5bPal7qZKkEe44PGzGJxSWfuM+n9QznX1AoGBANMA 16 | dUsYJonfjqnLFy1hH/7gyJM6Ldz6PzY7b9dRUK4Hkpu8zyXIcVklSLPOGOeZiPLN 17 | TKHpMc2RLkdB4TUnTu8MahQ6BEkSEVvxnDr/5NKGEFSnmgSGWxhKt4f8csvbi499 18 | Y98k13AohK242G6dbUxv4k0Tl8h8+kzQBXXOV4vhAoGASse4SyD3M+7joUWITmgD 19 | 1h1mnTc9baPwFazt7NG7Tox3GT8brLpx8/tQNb5y2TOajrqbtHIX8FCR7PHtsRpN 20 | Dqg2mQlGkG+7tAHx3wrMDTL5kY5SvmTat7pzY2PkWfIBIbpG7yylWw4uIVg89ThQ 21 | LmojGCxwkVLJ0JBqYfUW6vUCgYATfCNYv+4vJTnjbCHDywhNXSyoi+LYWTOlKm/1 22 | jkjJCWH8h78JWi09cjf4grvCB2eiJFtDSGmU9icz5V2KrwqXAKp7G7Bxnv2DZBht 23 | SlwzJLY1WxTZ/h5DbALux91B/hAxO/8RCDHs5ZD7CerSrC7/tAVN4NVPalsi5MLc 24 | UiW7gQKBgEiZ6DM3b0j9hPYxRtcwvwl+OiKEb5xd3YJ+OTsMNJk17K1gTCnFJKO/ 25 | p7ZTx+Sw4nGeJOa8Kt80A6Z3GhHiNu77DDTgZq7Z1sYAN6RPsknnhsoI0Bgd4Kq5 26 | DYc7em1KwHxK4mV52Ds5AV3zvpSeeGc/cjq8RlQ0Cnj69OCwxy9d 27 | -----END RSA PRIVATE KEY----- 28 | -------------------------------------------------------------------------------- /CMake/Platform.cmake: -------------------------------------------------------------------------------- 1 | IF(CMAKE_SYSTEM_NAME STREQUAL "Linux") 2 | SET(OS_LINUX true CACHE INTERNAL "Linux operating system") 3 | ELSEIF(CMAKE_SYSTEM_NAME STREQUAL "Darwin") 4 | SET(OS_MACOSX true CACHE INTERNAL "Mac Darwin operating system") 5 | ELSE(CMAKE_SYSTEM_NAME STREQUAL "Linux") 6 | MESSAGE(FATAL_ERROR "Unsupported OS: \"${CMAKE_SYSTEM_NAME}\"") 7 | ENDIF(CMAKE_SYSTEM_NAME STREQUAL "Linux") 8 | 9 | IF(CMAKE_COMPILER_IS_GNUCXX) 10 | EXECUTE_PROCESS(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_COMPILER_VERSION) 11 | 12 | IF (NOT GCC_COMPILER_VERSION) 13 | MESSAGE(FATAL_ERROR "Cannot get gcc version") 14 | ENDIF (NOT GCC_COMPILER_VERSION) 15 | 16 | STRING(REGEX MATCHALL "[0-9]+" GCC_COMPILER_VERSION ${GCC_COMPILER_VERSION}) 17 | 18 | LIST(GET GCC_COMPILER_VERSION 0 GCC_COMPILER_VERSION_MAJOR) 19 | LIST(GET GCC_COMPILER_VERSION 1 GCC_COMPILER_VERSION_MINOR) 20 | 21 | SET(GCC_COMPILER_VERSION_MAJOR ${GCC_COMPILER_VERSION_MAJOR} CACHE INTERNAL "gcc major version") 22 | SET(GCC_COMPILER_VERSION_MINOR ${GCC_COMPILER_VERSION_MINOR} CACHE INTERNAL "gcc minor version") 23 | 24 | MESSAGE(STATUS "checking compiler: GCC (${GCC_COMPILER_VERSION_MAJOR}.${GCC_COMPILER_VERSION_MINOR}.${GCC_COMPILER_VERSION_PATCH})") 25 | ELSE(CMAKE_COMPILER_IS_GNUCXX) 26 | EXECUTE_PROCESS(COMMAND ${CMAKE_C_COMPILER} --version OUTPUT_VARIABLE COMPILER_OUTPUT) 27 | IF(COMPILER_OUTPUT MATCHES "clang") 28 | SET(CMAKE_COMPILER_IS_CLANG true CACHE INTERNAL "using clang as compiler") 29 | MESSAGE(STATUS "checking compiler: CLANG") 30 | ELSE(COMPILER_OUTPUT MATCHES "clang") 31 | MESSAGE(FATAL_ERROR "Unsupported compiler: \"${CMAKE_CXX_COMPILER}\"") 32 | ENDIF(COMPILER_OUTPUT MATCHES "clang") 33 | ENDIF(CMAKE_COMPILER_IS_GNUCXX) 34 | -------------------------------------------------------------------------------- /src/block/OssBlockWorker.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * 2017 - 3 | * open source under Apache License Version 2.0 4 | ********************************************************************/ 5 | /** 6 | * Licensed to the Apache Software Foundation (ASF) under one 7 | * or more contributor license agreements. See the NOTICE file 8 | * distributed with this work for additional information 9 | * regarding copyright ownership. The ASF licenses this file 10 | * to you under the Apache License, Version 2.0 (the 11 | * "License"); you may not use this file except in compliance 12 | * with the License. You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | #ifndef GOPHERWOOD_BLOCK_OSSBLOCKWORKER_H 23 | #define GOPHERWOOD_BLOCK_OSSBLOCKWORKER_H 24 | 25 | #include "platform.h" 26 | #include "core/BlockStatus.h" 27 | #include "oss/oss.h" 28 | 29 | namespace Gopherwood { 30 | namespace Internal { 31 | 32 | class OssBlockWorker { 33 | public: 34 | OssBlockWorker(ossContext ossCtx, int localSpaceFD); 35 | 36 | void writeBlock(BlockInfo info); 37 | 38 | int64_t readBlock(BlockInfo info); 39 | 40 | void deleteBlock(BlockInfo info); 41 | 42 | ~OssBlockWorker(); 43 | 44 | private: 45 | std::string getOssObjectName(BlockInfo blockInfo); 46 | 47 | ossContext mOssContext; 48 | int mLocalSpaceFD; 49 | }; 50 | 51 | } 52 | } 53 | #endif //GOPHERWOOD_BLOCK_OSSBLOCKWORKER_H 54 | -------------------------------------------------------------------------------- /src/block/LocalBlockWriter.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * 2017 - 3 | * open source under Apache License Version 2.0 4 | ********************************************************************/ 5 | /** 6 | * Licensed to the Apache Software Foundation (ASF) under one 7 | * or more contributor license agreements. See the NOTICE file 8 | * distributed with this work for additional information 9 | * regarding copyright ownership. The ASF licenses this file 10 | * to you under the Apache License, Version 2.0 (the 11 | * "License"); you may not use this file except in compliance 12 | * with the License. You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | #ifndef GOPHERWOOD_BLOCK_LOCALBLOCKWRITER_H 23 | #define GOPHERWOOD_BLOCK_LOCALBLOCKWRITER_H 24 | 25 | #include "platform.h" 26 | 27 | #include "common/Memory.h" 28 | 29 | namespace Gopherwood { 30 | namespace Internal { 31 | 32 | class LocalBlockWriter { 33 | public: 34 | LocalBlockWriter(int fd); 35 | 36 | int seek(int64_t offset); 37 | 38 | int writeLocal(const char *buffer, int64_t length); 39 | 40 | void flush(); 41 | 42 | inline int64_t getCurOffset() { 43 | return mOffset; 44 | }; 45 | 46 | ~LocalBlockWriter(); 47 | 48 | private: 49 | int mLocalSpaceFD; 50 | int64_t mOffset; //offset of the local space file 51 | }; 52 | 53 | } 54 | } 55 | #endif //GOPHERWOOD_BLOCK_LOCALBLOCKWRITER_H 56 | -------------------------------------------------------------------------------- /src/common/OssBuilder.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * 2017 - 3 | * open source under Apache License Version 2.0 4 | ********************************************************************/ 5 | /** 6 | * Licensed to the Apache Software Foundation (ASF) under one 7 | * or more contributor license agreements. See the NOTICE file 8 | * distributed with this work for additional information 9 | * regarding copyright ownership. The ASF licenses this file 10 | * to you under the Apache License, Version 2.0 (the 11 | * "License"); you may not use this file except in compliance 12 | * with the License. You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | #ifndef GOPHERWOOD_COMMON_OSSBUILDER_H 23 | #define GOPHERWOOD_COMMON_OSSBUILDER_H 24 | 25 | #include "common/ObjectStorInfo.h" 26 | #include "oss/oss.h" 27 | #include "common/Memory.h" 28 | 29 | namespace Gopherwood { 30 | namespace Internal { 31 | 32 | class OssBuilder { 33 | public: 34 | static shared_ptr instance; 35 | 36 | OssBuilder(); 37 | 38 | static shared_ptr getInstance(); 39 | 40 | ossContext buildContext(); 41 | 42 | std::string getBucketName(); 43 | 44 | ~OssBuilder(); 45 | 46 | private: 47 | void buildOssInfo(); 48 | void setObjectStorInfo(); 49 | 50 | ObjectStorInfo mOssInfo; 51 | std::string mBucket; 52 | }; 53 | 54 | } 55 | } 56 | 57 | #endif //GOPHERWOOD_COMMON_OSSBUILDER_H 58 | -------------------------------------------------------------------------------- /src/network/Syscall.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * 2017 - 3 | * open source under Apache License Version 2.0 4 | ********************************************************************/ 5 | /** 6 | * Licensed to the Apache Software Foundation (ASF) under one 7 | * or more contributor license agreements. See the NOTICE file 8 | * distributed with this work for additional information 9 | * regarding copyright ownership. The ASF licenses this file 10 | * to you under the Apache License, Version 2.0 (the 11 | * "License"); you may not use this file except in compliance 12 | * with the License. You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | #ifndef _GOPHERWOOD_NETWORK_SYSCALL_H_ 23 | #define _GOPHERWOOD_NETWORK_SYSCALL_H_ 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | namespace System { 32 | 33 | using ::recv; 34 | using ::send; 35 | using ::getaddrinfo; 36 | using ::freeaddrinfo; 37 | using ::socket; 38 | using ::connect; 39 | using ::getpeername; 40 | using ::fcntl; 41 | using ::setsockopt; 42 | using ::poll; 43 | using ::shutdown; 44 | using ::close; 45 | using ::recvmsg; 46 | 47 | } 48 | 49 | #ifdef MOCK 50 | 51 | #include "MockSystem.h" 52 | namespace GopherwoodSystem = MockSystem; 53 | 54 | #else 55 | 56 | namespace GopherwoodSystem = System; 57 | 58 | #endif 59 | 60 | #endif /* _GOPHERWOOD_NETWORK_SYSCALL_H_ */ 61 | -------------------------------------------------------------------------------- /src/core/AdminActiveStatus.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * 2017 - 3 | * open source under Apache License Version 2.0 4 | ********************************************************************/ 5 | /** 6 | * Licensed to the Apache Software Foundation (ASF) under one 7 | * or more contributor license agreements. See the NOTICE file 8 | * distributed with this work for additional information 9 | * regarding copyright ownership. The ASF licenses this file 10 | * to you under the Apache License, Version 2.0 (the 11 | * "License"); you may not use this file except in compliance 12 | * with the License. You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | #ifndef _GOPHERWOOD_CORE_ADMINACTIVESTATUS_H_ 23 | #define _GOPHERWOOD_CORE_ADMINACTIVESTATUS_H_ 24 | 25 | #include "client/gopherwood.h" 26 | #include "core/BaseActiveStatus.h" 27 | 28 | namespace Gopherwood { 29 | namespace Internal { 30 | 31 | class AdminActiveStatus : BaseActiveStatus{ 32 | public: 33 | AdminActiveStatus(shared_ptr sharedMemoryContext, 34 | int localSpaceFD); 35 | 36 | void getShareMemStatistic(GWSysInfo* sysInfo); 37 | 38 | int32_t evictNumOfBlocks(int num); 39 | 40 | ~AdminActiveStatus(); 41 | 42 | private: 43 | void registInSharedMem(); 44 | void unregistInSharedMem(); 45 | 46 | void logEvictBlock(BlockInfo info); 47 | }; 48 | 49 | } 50 | } 51 | 52 | #endif //_GOPHERWOOD_CORE_ADMINACTIVESTATUS_H_ -------------------------------------------------------------------------------- /src/core/BaseActiveStatus.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * 2017 - 3 | * open source under Apache License Version 2.0 4 | ********************************************************************/ 5 | /** 6 | * Licensed to the Apache Software Foundation (ASF) under one 7 | * or more contributor license agreements. See the NOTICE file 8 | * distributed with this work for additional information 9 | * regarding copyright ownership. The ASF licenses this file 10 | * to you under the Apache License, Version 2.0 (the 11 | * "License"); you may not use this file except in compliance 12 | * with the License. You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | #include "common/Configuration.h" 23 | #include "core/BaseActiveStatus.h" 24 | #include "file/FileSystem.h" 25 | 26 | namespace Gopherwood { 27 | namespace Internal { 28 | 29 | BaseActiveStatus::BaseActiveStatus(shared_ptr sharedMemoryContext, 30 | int localSpaceFD) : 31 | mSharedMemoryContext(sharedMemoryContext), 32 | mLocalSpaceFD(localSpaceFD) { 33 | mOssWorker = shared_ptr(new OssBlockWorker(FileSystem::OSS_CONTEXT, mLocalSpaceFD)); 34 | 35 | mBucketSize = Configuration::LOCAL_BUCKET_SIZE; 36 | 37 | /* init statistics */ 38 | mNumEvicted = 0; 39 | mNumLoaded = 0; 40 | mNumActivated = 0; 41 | 42 | } 43 | 44 | BaseActiveStatus::~BaseActiveStatus() { 45 | 46 | } 47 | 48 | 49 | } 50 | } 51 | 52 | -------------------------------------------------------------------------------- /test/function/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | CMAKE_MINIMUM_REQUIRED(VERSION 2.8) 2 | 3 | AUTO_SOURCES(function_SOURCES "*.cpp" "RECURSE" "${CMAKE_CURRENT_SOURCE_DIR}") 4 | 5 | INCLUDE_DIRECTORIES(${gmock_INCLUDE_DIR} ${gtest_INCLUDE_DIR} ${libgopherwood_ROOT_SOURCES_DIR}) 6 | 7 | IF(NEED_BOOST) 8 | INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIR}) 9 | ENDIF(NEED_BOOST) 10 | 11 | INCLUDE_DIRECTORIES(${libgopherwood_ROOT_SOURCES_DIR}) 12 | INCLUDE_DIRECTORIES(${libgopherwood_COMMON_SOURCES_DIR}) 13 | INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}) 14 | INCLUDE_DIRECTORIES(${libgopherwood_PLATFORM_HEADER_DIR}) 15 | INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/mock) 16 | 17 | IF(ENABLE_DEBUG STREQUAL ON) 18 | SET(libgopherwood_SOURCES ${libgopherwood_SOURCES} ${libgopherwood_MOCK_SOURCES}) 19 | ENDIF(ENABLE_DEBUG STREQUAL ON) 20 | 21 | ADD_EXECUTABLE(function EXCLUDE_FROM_ALL 22 | ${gtest_SOURCES} 23 | ${gmock_SOURCES} 24 | ${libgopherwood_SOURCES} 25 | ${libgopherwood_PROTO_SOURCES} 26 | ${libgopherwood_PROTO_HEADERS} 27 | ${function_SOURCES} 28 | ) 29 | 30 | TARGET_LINK_LIBRARIES(function pthread) 31 | TARGET_LINK_LIBRARIES(function oss) 32 | 33 | IF(NEED_BOOST) 34 | INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIR}) 35 | SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L${Boost_LIBRARY_DIRS}") 36 | TARGET_LINK_LIBRARIES(function boost_thread) 37 | TARGET_LINK_LIBRARIES(function boost_chrono) 38 | TARGET_LINK_LIBRARIES(function boost_system) 39 | TARGET_LINK_LIBRARIES(function boost_atomic) 40 | TARGET_LINK_LIBRARIES(function boost_iostreams) 41 | ENDIF(NEED_BOOST) 42 | 43 | IF(NEED_GCCEH) 44 | TARGET_LINK_LIBRARIES(function gcc_eh) 45 | ENDIF(NEED_GCCEH) 46 | 47 | IF(OS_LINUX) 48 | TARGET_LINK_LIBRARIES(function ${LIBUUID_LIBRARIES}) 49 | INCLUDE_DIRECTORIES(${LIBUUID_INCLUDE_DIRS}) 50 | ENDIF(OS_LINUX) 51 | 52 | SET(function_SOURCES ${function_SOURCES} PARENT_SCOPE) 53 | 54 | 55 | -------------------------------------------------------------------------------- /CMake/CodeCoverage.cmake: -------------------------------------------------------------------------------- 1 | # Check prereqs 2 | FIND_PROGRAM(GCOV_PATH gcov) 3 | FIND_PROGRAM(LCOV_PATH lcov) 4 | FIND_PROGRAM(GENHTML_PATH genhtml) 5 | 6 | IF(NOT GCOV_PATH) 7 | MESSAGE(FATAL_ERROR "gcov not found! Aborting...") 8 | ENDIF(NOT GCOV_PATH) 9 | 10 | IF(NOT CMAKE_BUILD_TYPE STREQUAL Debug) 11 | MESSAGE(WARNING "Code coverage results with an optimised (non-Debug) build may be misleading") 12 | ENDIF(NOT CMAKE_BUILD_TYPE STREQUAL Debug) 13 | 14 | #Setup compiler options 15 | ADD_DEFINITIONS(-fprofile-arcs -ftest-coverage) 16 | 17 | SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs ") 18 | SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fprofile-arcs ") 19 | 20 | IF(NOT LCOV_PATH) 21 | MESSAGE(FATAL_ERROR "lcov not found! Aborting...") 22 | ENDIF(NOT LCOV_PATH) 23 | 24 | IF(NOT GENHTML_PATH) 25 | MESSAGE(FATAL_ERROR "genhtml not found! Aborting...") 26 | ENDIF(NOT GENHTML_PATH) 27 | 28 | #Setup target 29 | ADD_CUSTOM_TARGET(ShowCoverage 30 | #Capturing lcov counters and generating report 31 | COMMAND ${LCOV_PATH} --directory . --capture --output-file CodeCoverage.info 32 | COMMAND ${LCOV_PATH} --remove CodeCoverage.info '${CMAKE_CURRENT_BINARY_DIR}/*' 'test/*' 'mock/*' '/usr/*' '*ext/rhel5_x86_64*' '*ext/osx*' --output-file CodeCoverage.info.cleaned 33 | COMMAND ${GENHTML_PATH} -o CodeCoverageReport CodeCoverage.info.cleaned 34 | ) 35 | 36 | 37 | ADD_CUSTOM_TARGET(ShowAllCoverage 38 | #Capturing lcov counters and generating report 39 | COMMAND ${LCOV_PATH} -a CodeCoverage.info.cleaned -a CodeCoverage.info.cleaned_withoutHA -o AllCodeCoverage.info 40 | COMMAND sed -e 's|/.*/src|${CMAKE_SOURCE_DIR}/src|' -ig AllCodeCoverage.info 41 | COMMAND ${GENHTML_PATH} -o AllCodeCoverageReport AllCodeCoverage.info 42 | ) 43 | 44 | ADD_CUSTOM_TARGET(ResetCoverage 45 | #Cleanup lcov 46 | COMMAND ${LCOV_PATH} --directory . --zerocounters 47 | ) 48 | 49 | -------------------------------------------------------------------------------- /src/file/InputStream.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * 2017 - 3 | * open source under Apache License Version 2.0 4 | ********************************************************************/ 5 | /** 6 | * Licensed to the Apache Software Foundation (ASF) under one 7 | * or more contributor license agreements. See the NOTICE file 8 | * distributed with this work for additional information 9 | * regarding copyright ownership. The ASF licenses this file 10 | * to you under the Apache License, Version 2.0 (the 11 | * "License"); you may not use this file except in compliance 12 | * with the License. You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | #ifndef _GOPHERWOOD_FILE_INPUTSTREAM_H_ 23 | #define _GOPHERWOOD_FILE_INPUTSTREAM_H_ 24 | 25 | #include "platform.h" 26 | 27 | #include "block/BlockInputStream.h" 28 | #include "common/Memory.h" 29 | #include "core/FileActiveStatus.h" 30 | #include "oss/oss.h" 31 | 32 | namespace Gopherwood { 33 | namespace Internal { 34 | 35 | class InputStream { 36 | public: 37 | InputStream(int fd, shared_ptr status); 38 | 39 | void read(char *buffer, int64_t length); 40 | 41 | void close(); 42 | 43 | ~InputStream(); 44 | 45 | private: 46 | void updateBlockStream(); 47 | 48 | int mLocalSpaceFD; 49 | shared_ptr mStatus; 50 | shared_ptr mBlockInputStream; 51 | int64_t mPos; 52 | }; 53 | 54 | } 55 | } 56 | 57 | #endif //_GOPHERWOOD_FILE_INPUTSTREAM_H_ 58 | -------------------------------------------------------------------------------- /src/common/Configuration.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * 2017 - 3 | * open source under Apache License Version 2.0 4 | ********************************************************************/ 5 | /** 6 | * Licensed to the Apache Software Foundation (ASF) under one 7 | * or more contributor license agreements. See the NOTICE file 8 | * distributed with this work for additional information 9 | * regarding copyright ownership. The ASF licenses this file 10 | * to you under the Apache License, Version 2.0 (the 11 | * "License"); you may not use this file except in compliance 12 | * with the License. You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | 23 | #ifndef _GOPHERWOOD_COMMON_CONFIGURATION_H_ 24 | #define _GOPHERWOOD_COMMON_CONFIGURATION_H_ 25 | 26 | #include 27 | 28 | namespace Gopherwood { 29 | namespace Internal { 30 | 31 | class Configuration { 32 | public: 33 | static std::string LOCAL_SPACE_FILE; 34 | static std::string SHARED_MEMORY_NAME; 35 | static std::string MANIFEST_FOLDER; 36 | static int32_t NUMBER_OF_BLOCKS; 37 | static int64_t LOCAL_BUCKET_SIZE; 38 | static uint16_t MAX_CONNECTION; 39 | static int CUR_CONNECTION; 40 | static uint32_t PRE_ALLOCATE_BUCKET_NUM; 41 | static int32_t PRE_ACTIVATE_BLOCK_NUM; 42 | 43 | /* hard coded parameters */ 44 | static size_t MAX_LOADER_THREADS; 45 | 46 | static uint32_t getCurQuotaSize(); 47 | }; 48 | 49 | 50 | } 51 | } 52 | 53 | #endif /* _GOPHERWOOD_COMMON_CONFIGURATION_H_ */ 54 | -------------------------------------------------------------------------------- /src/common/Configuration.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * 2017 - 3 | * open source under Apache License Version 2.0 4 | ********************************************************************/ 5 | /** 6 | * Licensed to the Apache Software Foundation (ASF) under one 7 | * or more contributor license agreements. See the NOTICE file 8 | * distributed with this work for additional information 9 | * regarding copyright ownership. The ASF licenses this file 10 | * to you under the Apache License, Version 2.0 (the 11 | * "License"); you may not use this file except in compliance 12 | * with the License. You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | #include "Configuration.h" 23 | 24 | namespace Gopherwood { 25 | namespace Internal { 26 | 27 | std::string Configuration::LOCAL_SPACE_FILE("GopherwoodLocal"); 28 | std::string Configuration::SHARED_MEMORY_NAME("GopherwoodSharedMem"); 29 | std::string Configuration::MANIFEST_FOLDER("/manifest"); 30 | 31 | int32_t Configuration::NUMBER_OF_BLOCKS = 100; 32 | 33 | int64_t Configuration::LOCAL_BUCKET_SIZE = 64 * 1024 * 1024; 34 | 35 | uint16_t Configuration::MAX_CONNECTION = 1024; 36 | 37 | int Configuration::CUR_CONNECTION = 10; 38 | 39 | uint32_t Configuration::PRE_ALLOCATE_BUCKET_NUM = 4; 40 | 41 | int32_t Configuration::PRE_ACTIVATE_BLOCK_NUM = 4; 42 | 43 | size_t Configuration::MAX_LOADER_THREADS = 5; 44 | 45 | uint32_t Configuration::getCurQuotaSize(){ 46 | return Configuration::NUMBER_OF_BLOCKS/Configuration::CUR_CONNECTION; 47 | } 48 | 49 | } 50 | } 51 | 52 | -------------------------------------------------------------------------------- /src/file/OutputStream.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * 2017 - 3 | * open source under Apache License Version 2.0 4 | ********************************************************************/ 5 | /** 6 | * Licensed to the Apache Software Foundation (ASF) under one 7 | * or more contributor license agreements. See the NOTICE file 8 | * distributed with this work for additional information 9 | * regarding copyright ownership. The ASF licenses this file 10 | * to you under the Apache License, Version 2.0 (the 11 | * "License"); you may not use this file except in compliance 12 | * with the License. You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | #ifndef _GOPHERWOOD_FILE_OUTPUTSTREAM_H_ 23 | #define _GOPHERWOOD_FILE_OUTPUTSTREAM_H_ 24 | 25 | #include "platform.h" 26 | 27 | #include "block/BlockOutputStream.h" 28 | #include "common/Memory.h" 29 | #include "core/FileActiveStatus.h" 30 | #include "oss/oss.h" 31 | 32 | namespace Gopherwood { 33 | namespace Internal { 34 | class OutputStream { 35 | public: 36 | OutputStream(int fd, shared_ptr status); 37 | 38 | void write(const char *buffer, int64_t length, bool isSeek); 39 | 40 | void flush(); 41 | 42 | void close(); 43 | 44 | ~OutputStream(); 45 | 46 | private: 47 | void updateBlockStream(); 48 | 49 | int mLocalSpaceFD; 50 | shared_ptr mBlockOutputStream; 51 | shared_ptr mStatus; 52 | int64_t mPos; 53 | }; 54 | 55 | } 56 | } 57 | 58 | #endif //_GOPHERWOOD_FILE_OUTPUTSTREAM_H_ 59 | -------------------------------------------------------------------------------- /src/common/Logger.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * 2017 - 3 | * open source under Apache License Version 2.0 4 | ********************************************************************/ 5 | /** 6 | * Licensed to the Apache Software Foundation (ASF) under one 7 | * or more contributor license agreements. See the NOTICE file 8 | * distributed with this work for additional information 9 | * regarding copyright ownership. The ASF licenses this file 10 | * to you under the Apache License, Version 2.0 (the 11 | * "License"); you may not use this file except in compliance 12 | * with the License. You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | #ifndef _GOPHERWOOD_COMMON_LOGGER_H_ 23 | #define _GOPHERWOOD_COMMON_LOGGER_H_ 24 | 25 | #define DEFAULT_LOG_LEVEL INFO 26 | 27 | namespace Gopherwood { 28 | namespace Internal { 29 | 30 | extern const char *SeverityName[7]; 31 | 32 | enum LogSeverity { 33 | FATAL, LOG_ERROR, WARNING, INFO, DEBUG1, DEBUG2, DEBUG3 34 | }; 35 | 36 | class Logger; 37 | 38 | class Logger { 39 | public: 40 | Logger(); 41 | 42 | ~Logger(); 43 | 44 | void setOutputFd(int f); 45 | 46 | void setLogSeverity(LogSeverity l); 47 | 48 | void printf(LogSeverity s, const char *fmt, ...) __attribute__((format(printf, 3, 4))); 49 | 50 | private: 51 | int fd; 52 | LogSeverity severity; 53 | }; 54 | 55 | extern Logger RootLogger; 56 | 57 | } 58 | } 59 | 60 | #define LOG(s, fmt, ...) \ 61 | Gopherwood::Internal::RootLogger.printf(s, fmt, ##__VA_ARGS__) 62 | 63 | #endif /* _GOPHERWOOD_COMMON_LOGGER_H_ */ 64 | -------------------------------------------------------------------------------- /src/core/BaseActiveStatus.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * 2017 - 3 | * open source under Apache License Version 2.0 4 | ********************************************************************/ 5 | /** 6 | * Licensed to the Apache Software Foundation (ASF) under one 7 | * or more contributor license agreements. See the NOTICE file 8 | * distributed with this work for additional information 9 | * regarding copyright ownership. The ASF licenses this file 10 | * to you under the Apache License, Version 2.0 (the 11 | * "License"); you may not use this file except in compliance 12 | * with the License. You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | #ifndef _GOPHERWOOD_CORE_BASEACTIVESTATUS_H_ 23 | #define _GOPHERWOOD_CORE_BASEACTIVESTATUS_H_ 24 | 25 | #include "block/OssBlockWorker.h" 26 | #include "core/SharedMemoryContext.h" 27 | 28 | namespace Gopherwood { 29 | namespace Internal { 30 | 31 | class BaseActiveStatus { 32 | public: 33 | 34 | BaseActiveStatus(shared_ptr sharedMemoryContext, 35 | int localSpaceFD); 36 | 37 | virtual ~BaseActiveStatus(); 38 | 39 | protected: 40 | shared_ptr mSharedMemoryContext; 41 | shared_ptr mOssWorker; 42 | int16_t mActiveId; 43 | int mLocalSpaceFD; 44 | int64_t mBucketSize; 45 | 46 | /**************** Statistics ****************/ 47 | uint32_t mNumEvicted; 48 | uint32_t mNumLoaded; 49 | uint32_t mNumActivated; 50 | }; 51 | 52 | } 53 | } 54 | 55 | 56 | #endif //_GOPHERWOOD_CORE_BASEACTIVESTATUS_H_ 57 | -------------------------------------------------------------------------------- /src/block/BlockInputStream.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * 2017 - 3 | * open source under Apache License Version 2.0 4 | ********************************************************************/ 5 | /** 6 | * Licensed to the Apache Software Foundation (ASF) under one 7 | * or more contributor license agreements. See the NOTICE file 8 | * distributed with this work for additional information 9 | * regarding copyright ownership. The ASF licenses this file 10 | * to you under the Apache License, Version 2.0 (the 11 | * "License"); you may not use this file except in compliance 12 | * with the License. You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | #ifndef GOPHERWOOD_BLOCK_BLOCKINPUTSTREAM_H 23 | #define GOPHERWOOD_BLOCK_BLOCKINPUTSTREAM_H 24 | 25 | #include "platform.h" 26 | 27 | #include "block/LocalBlockReader.h" 28 | #include "block/OssBlockWorker.h" 29 | #include "core/FileActiveStatus.h" 30 | #include "common/Memory.h" 31 | #include "oss/oss.h" 32 | 33 | namespace Gopherwood { 34 | namespace Internal { 35 | class BlockInputStream { 36 | public: 37 | BlockInputStream(int fd); 38 | 39 | void setBlockInfo(BlockInfo info); 40 | 41 | int64_t remaining(); 42 | 43 | int64_t read(char *buffer, int64_t length); 44 | 45 | void flush(); 46 | 47 | ~BlockInputStream(); 48 | 49 | private: 50 | int64_t getLocalSpaceOffset(); 51 | 52 | int mLocalSpaceFD; 53 | int64_t mBucketSize; 54 | BlockInfo mBlockInfo; 55 | shared_ptr mLocalReader; 56 | shared_ptr mOssWorker; 57 | }; 58 | 59 | } 60 | } 61 | #endif //GOPHERWOOD_BLOCK_BLOCKINPUTSTREAM_H 62 | -------------------------------------------------------------------------------- /src/block/BlockOutputStream.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * 2017 - 3 | * open source under Apache License Version 2.0 4 | ********************************************************************/ 5 | /** 6 | * Licensed to the Apache Software Foundation (ASF) under one 7 | * or more contributor license agreements. See the NOTICE file 8 | * distributed with this work for additional information 9 | * regarding copyright ownership. The ASF licenses this file 10 | * to you under the Apache License, Version 2.0 (the 11 | * "License"); you may not use this file except in compliance 12 | * with the License. You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | #ifndef _GOPHERWOOD_BLOCK_BLOCKOUTPUTSTREAM_H_ 23 | #define _GOPHERWOOD_BLOCK_BLOCKOUTPUTSTREAM_H_ 24 | 25 | #include "platform.h" 26 | 27 | #include "block/LocalBlockWriter.h" 28 | #include "core/FileActiveStatus.h" 29 | #include "common/Memory.h" 30 | #include "oss/oss.h" 31 | #include "OssBlockWorker.h" 32 | 33 | namespace Gopherwood { 34 | namespace Internal { 35 | class BlockOutputStream { 36 | public: 37 | BlockOutputStream(int fd); 38 | 39 | void setBlockInfo(BlockInfo info); 40 | 41 | int64_t remaining(); 42 | 43 | int64_t write(const char *buffer, int64_t length); 44 | 45 | void flush(); 46 | 47 | ~BlockOutputStream(); 48 | 49 | private: 50 | int64_t getLocalSpaceOffset(); 51 | 52 | int mLocalSpaceFD; 53 | int64_t mBucketSize; 54 | BlockInfo mBlockInfo; 55 | bool mCached; 56 | 57 | shared_ptr mLocalWriter; 58 | shared_ptr mOssWorker; 59 | }; 60 | 61 | } 62 | } 63 | 64 | #endif //_GOPHERWOOD_BLOCK_BLOCKOUTPUTSTREAM_H_ 65 | -------------------------------------------------------------------------------- /CMakeLists-bak.txt: -------------------------------------------------------------------------------- 1 | CMAKE_MINIMUM_REQUIRED(VERSION 2.8) 2 | 3 | PROJECT(libgopherwood) 4 | 5 | SET(CMAKE_VERBOSE_MAKEFILE ON CACHE STRING "Verbose build." FORCE) 6 | 7 | IF(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR}) 8 | MESSAGE(FATAL_ERROR "cannot build the project in the source directory! Out-of-source build is enforced!") 9 | ENDIF() 10 | 11 | SET(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake" ${CMAKE_MODULE_PATH}) 12 | SET(DOXYFILE_PATH ${CMAKE_SOURCE_DIR}/docs) 13 | 14 | INCLUDE(Platform) 15 | INCLUDE(Functions) 16 | INCLUDE(Options) 17 | 18 | FIND_PACKAGE(Boost REQUIRED) 19 | FIND_PACKAGE(Liboss REQUIRED) 20 | 21 | ADD_SUBDIRECTORY(mock) 22 | ADD_SUBDIRECTORY(src) 23 | ADD_SUBDIRECTORY(gtest) 24 | ADD_SUBDIRECTORY(gmock) 25 | ADD_SUBDIRECTORY(test) 26 | ADD_SUBDIRECTORY(sample) 27 | 28 | CONFIGURE_FILE(src/libgopherwood.pc.in ${CMAKE_SOURCE_DIR}/src/libgopherwood.pc @ONLY) 29 | 30 | ADD_CUSTOM_TARGET(doc 31 | COMMAND doxygen ${CMAKE_BINARY_DIR}/src/doxyfile 32 | WORKING_DIRECTORY ${DOXYFILE_PATH} 33 | COMMENT "Generate documents..." 34 | ) 35 | 36 | ADD_CUSTOM_TARGET(style 37 | COMMAND astyle --style=attach --indent=spaces=4 --indent-preprocessor --break-blocks --pad-oper --pad-header --unpad-paren --delete-empty-lines --suffix=none --align-pointer=middle --lineend=linux --indent-col1-comments ${libgopherwood_SOURCES} 38 | COMMAND astyle --style=attach --indent=spaces=4 --indent-preprocessor --break-blocks --pad-oper --pad-header --unpad-paren --delete-empty-lines --suffix=none --align-pointer=middle --lineend=linux --indent-col1-comments ${unit_SOURCES} 39 | COMMAND astyle --style=attach --indent=spaces=4 --indent-preprocessor --break-blocks --pad-oper --pad-header --unpad-paren --delete-empty-lines --suffix=none --align-pointer=middle --lineend=linux --indent-col1-comments ${function_SOURCES} 40 | COMMAND astyle --style=attach --indent=spaces=4 --indent-preprocessor --break-blocks --pad-oper --pad-header --unpad-paren --delete-empty-lines --suffix=none --align-pointer=middle --lineend=linux --indent-col1-comments ${secure_SOURCES} 41 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} 42 | COMMENT "format code style..." 43 | ) 44 | 45 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | CMAKE_MINIMUM_REQUIRED(VERSION 2.8) 2 | 3 | PROJECT(libgopherwood) 4 | 5 | SET(CMAKE_VERBOSE_MAKEFILE ON CACHE STRING "Verbose build." FORCE) 6 | 7 | IF(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR}) 8 | MESSAGE(FATAL_ERROR "cannot build the project in the source directory! Out-of-source build is enforced!") 9 | ENDIF() 10 | 11 | SET(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake" ${CMAKE_MODULE_PATH}) 12 | SET(DOXYFILE_PATH ${CMAKE_SOURCE_DIR}/docs) 13 | 14 | INCLUDE(Platform) 15 | INCLUDE(Functions) 16 | INCLUDE(Options) 17 | 18 | FIND_PACKAGE(Boost REQUIRED) 19 | FIND_PACKAGE(Liboss REQUIRED) 20 | 21 | ADD_SUBDIRECTORY(mock) 22 | ADD_SUBDIRECTORY(src) 23 | ADD_SUBDIRECTORY(gtest) 24 | ADD_SUBDIRECTORY(gmock) 25 | ADD_SUBDIRECTORY(test) 26 | ADD_SUBDIRECTORY(sample) 27 | 28 | CONFIGURE_FILE(src/libgopherwood.pc.in ${CMAKE_SOURCE_DIR}/src/libgopherwood.pc @ONLY) 29 | 30 | ADD_CUSTOM_TARGET(doc 31 | COMMAND doxygen ${CMAKE_BINARY_DIR}/src/doxyfile 32 | WORKING_DIRECTORY ${DOXYFILE_PATH} 33 | COMMENT "Generate documents..." 34 | ) 35 | 36 | ADD_CUSTOM_TARGET(style 37 | COMMAND astyle --style=attach --indent=spaces=4 --indent-preprocessor --break-blocks --pad-oper --pad-header --unpad-paren --delete-empty-lines --suffix=none --align-pointer=middle --lineend=linux --indent-col1-comments ${libgopherwood_SOURCES} 38 | COMMAND astyle --style=attach --indent=spaces=4 --indent-preprocessor --break-blocks --pad-oper --pad-header --unpad-paren --delete-empty-lines --suffix=none --align-pointer=middle --lineend=linux --indent-col1-comments ${unit_SOURCES} 39 | COMMAND astyle --style=attach --indent=spaces=4 --indent-preprocessor --break-blocks --pad-oper --pad-header --unpad-paren --delete-empty-lines --suffix=none --align-pointer=middle --lineend=linux --indent-col1-comments ${function_SOURCES} 40 | COMMAND astyle --style=attach --indent=spaces=4 --indent-preprocessor --break-blocks --pad-oper --pad-header --unpad-paren --delete-empty-lines --suffix=none --align-pointer=middle --lineend=linux --indent-col1-comments ${secure_SOURCES} 41 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} 42 | COMMENT "format code style..." 43 | ) 44 | 45 | -------------------------------------------------------------------------------- /src/common/DateTime.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * 2017 - 3 | * open source under Apache License Version 2.0 4 | ********************************************************************/ 5 | /** 6 | * Licensed to the Apache Software Foundation (ASF) under one 7 | * or more contributor license agreements. See the NOTICE file 8 | * distributed with this work for additional information 9 | * regarding copyright ownership. The ASF licenses this file 10 | * to you under the Apache License, Version 2.0 (the 11 | * "License"); you may not use this file except in compliance 12 | * with the License. You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | #ifndef _GOPHERWOOD_COMMON_DATETIME_H_ 23 | #define _GOPHERWOOD_COMMON_DATETIME_H_ 24 | 25 | #include "platform.h" 26 | 27 | #include 28 | #include 29 | 30 | #if defined(NEED_BOOST) && defined(HAVE_BOOST_CHRONO) 31 | 32 | #include 33 | 34 | namespace Gopherwood { 35 | namespace Internal { 36 | 37 | using namespace boost::chrono; 38 | 39 | } 40 | } 41 | 42 | #elif defined(HAVE_STD_CHRONO) 43 | 44 | #include 45 | 46 | namespace Gopherwood { 47 | namespace Internal { 48 | 49 | using namespace std::chrono; 50 | 51 | #ifndef HAVE_STEADY_CLOCK 52 | typedef std::chrono::monotonic_clock steady_clock; 53 | #endif 54 | 55 | } 56 | } 57 | #else 58 | #error "no chrono library is available" 59 | #endif 60 | 61 | namespace Gopherwood { 62 | namespace Internal { 63 | 64 | template 65 | static int64_t ToMilliSeconds(TimeStamp const & s, TimeStamp const & e) { 66 | assert(e >= s); 67 | return duration_cast(e - s).count(); 68 | } 69 | 70 | } 71 | } 72 | 73 | #endif /* _GOPHERWOOD_COMMON_DATETIME_H_ */ 74 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Gopherwood 2 | 3 | Gopherwood is an embedded persistent caching library with infinite space by leveraging object storage. It 4 | provides unified filesystem APIs for local caching files and supports offloading data to Object 5 | Store Service transparently when caching size exceeded the local disk volume. A block-based metadata 6 | system is designed to support infinite caching space, multi-process accessing, data persistent and 7 | caching recovery. 8 | 9 | The project is created to help on-premise system easily transform to cloud-oriented system. Using object 10 | store service will help solve the data high availability issues and lower the disk cost by configuring a 11 | minimum local disk quota. 12 | 13 | See the [github wiki](https://github.com/neuyilan/Gopherwood/wiki) for detailed documentations, developer guides and FAQs. 14 | 15 | ## Installation 16 | ### Requirement 17 | To build Gopherwood, the following libraries are needed. 18 | 19 | cmake (2.8+) http://www.cmake.org/ 20 | boost (tested on 1.53+) http://www.boost.org/ 21 | liboss binary integrated in project, will open source later 22 | To run tests, the following libraries are needed. 23 | 24 | gtest (tested on 1.7.0) already integrated in the source code 25 | gmock (tested on 1.7.0) already integrated in the source code 26 | 27 | To run code coverage test, the following tools are needed. 28 | 29 | gcov (included in gcc distribution) 30 | lcov (tested on 1.9) http://ltp.sourceforge.net/coverage/lcov.php 31 | ### Configuration, Build and Install 32 | cd GOPHERWOOD_HOME 33 | mkdir build 34 | cd build 35 | ../bootstrap 36 | Run command "../bootstrap --help" for more configuration. 37 | 38 | make 39 | make install 40 | 41 | ### Configurations of Object Storage Service 42 | modify $GOPHERWOOD_HOME/config.properties 43 | export GOPHERWOOD_CONF=$GOPHERWOOD_HOME/config.properties 44 | 45 | ### Test 46 | To test all test cases, run command 47 | 48 | make testAll 49 | 50 | To do function test, run command 51 | 52 | make functiontest 53 | 54 | To show code coverage result, run command. Code coverage result can be found at BUILD_DIR/CodeCoverageReport/index.html 55 | 56 | make ShowCoverage 57 | -------------------------------------------------------------------------------- /src/file/FileId.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * 2017 - 3 | * open source under Apache License Version 2.0 4 | ********************************************************************/ 5 | /** 6 | * Licensed to the Apache Software Foundation (ASF) under one 7 | * or more contributor license agreements. See the NOTICE file 8 | * distributed with this work for additional information 9 | * regarding copyright ownership. The ASF licenses this file 10 | * to you under the Apache License, Version 2.0 (the 11 | * "License"); you may not use this file except in compliance 12 | * with the License. You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | #ifndef _GOPHERWOOD_CORE_FILEID_H_ 23 | #define _GOPHERWOOD_CORE_FILEID_H_ 24 | 25 | #include "platform.h" 26 | 27 | #include "common/Unordered.h" 28 | #include 29 | 30 | namespace Gopherwood { 31 | namespace Internal { 32 | 33 | struct FileId { 34 | 35 | size_t hashcode; 36 | uint32_t collisionId; 37 | 38 | FileId() : hashcode(0), collisionId(0) {}; 39 | 40 | void reset() { 41 | hashcode = -1; 42 | collisionId = -1; 43 | } 44 | 45 | std::string toString() { 46 | std::stringstream ss; 47 | ss << hashcode << collisionId; 48 | std::string res = ss.str(); 49 | return res; 50 | } 51 | 52 | bool operator==(const FileId &rhs) const { 53 | if (hashcode != rhs.hashcode || 54 | collisionId != rhs.collisionId) { 55 | return false; 56 | } else { 57 | return true; 58 | } 59 | } 60 | 61 | bool operator!=(const FileId &rhs) const { 62 | if (hashcode != rhs.hashcode || 63 | collisionId != rhs.collisionId) { 64 | return true; 65 | } else { 66 | return false; 67 | } 68 | } 69 | }; 70 | 71 | } 72 | } 73 | 74 | #endif //_GOPHERWOOD_CORE_FILEID_H_ 75 | -------------------------------------------------------------------------------- /vagrant/Vagrantfile: -------------------------------------------------------------------------------- 1 | # Original Authors: Navneet Potti, Nabarun Nag and Jignesh Patel 2 | require 'yaml' 3 | 4 | # IP Address for the private VM network 5 | ip_address = "192.168.10.200" 6 | 7 | # Basic Vagrant config (API version 2) 8 | Vagrant.configure(2) do |config| 9 | 10 | # Base box: Centos-7 box 11 | # NOTE: Over time the VMI below may become outdated, so may need to be 12 | # substituted with a more recent VMI 13 | config.vm.box = "bento/centos-7.2" 14 | # config.vm.box = "box-cutter/centos72" 15 | 16 | # Make this VM reachable on the host network as well, so that other 17 | # VM's running other browsers can access our dev server. 18 | config.vm.network :private_network, ip: ip_address 19 | 20 | config.ssh.forward_x11 = true 21 | config.ssh.forward_agent = true 22 | 23 | # Give a reasonable amount of cpu and memory to the VM 24 | config.vm.provider "virtualbox" do |vb| 25 | vb.name = "libgopherwood-dev-host" # Name in VirtualBox 26 | vb.memory = 8192 27 | vb.cpus = 4 28 | vb.customize ["guestproperty", "set", :id, "/VirtualBox/GuestAdd/VBoxService/--timesync-set-threshold", "1000"] 29 | vb.customize ["guestproperty", "set", :id, "/VirtualBox/GuestAdd/VBoxService/--timesync-set-start"] 30 | vb.customize ["guestproperty", "set", :id, "/VirtualBox/GuestAdd/VBoxService/--timesync-set-on-restore", "1"] 31 | end 32 | 33 | # Make the GPDB code folder will be visible as /gpdb in the virtual machine 34 | config.vm.synced_folder "../.", "/gopherwood", owner: 555, group: 555 35 | 36 | if File.file?('vagrant-local.yml') 37 | local_config = YAML::load_file('vagrant-local.yml') 38 | local_config['synced_folder'].each do |folder| 39 | config.vm.synced_folder folder['local'], folder['shared'] unless folder['local'].nil? or folder['shared'].nil? 40 | end 41 | end 42 | 43 | # config ssh 44 | config.vm.provision "ssh", type: "shell", path: "vagrant-ssh.sh" 45 | 46 | # Install packages that are needed to build and run GPDB 47 | config.vm.provision "shell", path: "vagrant-setup.sh" 48 | 49 | default_name = "default" 50 | # use the trick to change user hashdata after "vagrant up" 51 | if File.file?('.vagrant/machines/' + default_name + '/virtualbox/id') 52 | config.ssh.username = "hashdata" 53 | config.ssh.private_key_path = "./id_rsa" 54 | end 55 | 56 | end 57 | -------------------------------------------------------------------------------- /src/file/File.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * 2017 - 3 | * open source under Apache License Version 2.0 4 | ********************************************************************/ 5 | /** 6 | * Licensed to the Apache Software Foundation (ASF) under one 7 | * or more contributor license agreements. See the NOTICE file 8 | * distributed with this work for additional information 9 | * regarding copyright ownership. The ASF licenses this file 10 | * to you under the Apache License, Version 2.0 (the 11 | * "License"); you may not use this file except in compliance 12 | * with the License. You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | #ifndef _GOPHERWOOD_CORE_FILE_H_ 23 | #define _GOPHERWOOD_CORE_FILE_H_ 24 | 25 | #include "platform.h" 26 | 27 | #include "client/gopherwood.h" 28 | #include "core/FileActiveStatus.h" 29 | #include "common/Memory.h" 30 | #include "file/OutputStream.h" 31 | #include "file/InputStream.h" 32 | #include "oss/oss.h" 33 | 34 | namespace Gopherwood { 35 | namespace Internal { 36 | 37 | #define OPEN_TYPE_MASK 0x00000003 38 | 39 | class File { 40 | public: 41 | File(FileId id, std::string fileName, int flags, int fd, shared_ptr status); 42 | 43 | int64_t read(char *buffer, int64_t length); 44 | 45 | void write(const char *buffer, int64_t length); 46 | 47 | void flush(); 48 | 49 | int64_t seek(int64_t pos, int mode); 50 | 51 | void close(bool isCancel); 52 | 53 | int64_t remaining(); 54 | 55 | FileId getFileId(); 56 | 57 | void getFileInfo(GWFileInfo *fileInfo); 58 | 59 | ~File(); 60 | 61 | private: 62 | FileId id; 63 | std::string name; 64 | std::string nameDigest; 65 | int mFlags; 66 | int localFD; 67 | shared_ptr mStatus; 68 | shared_ptr mOutStream; 69 | shared_ptr mInStream; 70 | }; 71 | 72 | } 73 | } 74 | 75 | #endif //_GOPHERWOOD_CORE_FILE_H_ 76 | -------------------------------------------------------------------------------- /src/core/SharedMemoryManager.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * 2017 - 3 | * open source under Apache License Version 2.0 4 | ********************************************************************/ 5 | /** 6 | * Licensed to the Apache Software Foundation (ASF) under one 7 | * or more contributor license agreements. See the NOTICE file 8 | * distributed with this work for additional information 9 | * regarding copyright ownership. The ASF licenses this file 10 | * to you under the Apache License, Version 2.0 (the 11 | * "License"); you may not use this file except in compliance 12 | * with the License. You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | #ifndef _GOPHERWOOD_CORE_SHAREDMEMORYMANAGER_H_ 23 | #define _GOPHERWOOD_CORE_SHAREDMEMORYMANAGER_H_ 24 | 25 | #include "platform.h" 26 | 27 | #include "common/Memory.h" 28 | #include "core/SharedMemoryContext.h" 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | namespace Gopherwood { 37 | namespace Internal { 38 | 39 | class SharedMemoryManager { 40 | public: 41 | static shared_ptr getInstance() { 42 | if (!instance) 43 | instance = shared_ptr(new SharedMemoryManager()); 44 | return instance; 45 | }; 46 | 47 | shared_ptr buildSharedMemoryContext(const char *workDir, int32_t lockFD); 48 | 49 | private: 50 | shared_ptr createSharedMemory(const char *name); 51 | 52 | shared_ptr openSharedMemory(const char *name, bool *exist); 53 | 54 | void rebuildShmFromManifest(shared_ptr ctx); 55 | 56 | static shared_ptr instance; 57 | }; 58 | 59 | } 60 | } 61 | 62 | #endif //_GOPHERWOOD_CORE_SHAREDMEMORYMANAGER_H_ 63 | -------------------------------------------------------------------------------- /src/core/ActiveStatusContext.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * 2017 - 3 | * open source under Apache License Version 2.0 4 | ********************************************************************/ 5 | /** 6 | * Licensed to the Apache Software Foundation (ASF) under one 7 | * or more contributor license agreements. See the NOTICE file 8 | * distributed with this work for additional information 9 | * regarding copyright ownership. The ASF licenses this file 10 | * to you under the Apache License, Version 2.0 (the 11 | * "License"); you may not use this file except in compliance 12 | * with the License. You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | #ifndef _GOPHERWOOD_CORE_ACTIVESTATUSCONTEXT_H_ 23 | #define _GOPHERWOOD_CORE_ACTIVESTATUSCONTEXT_H_ 24 | 25 | #include "platform.h" 26 | 27 | #include "file/FileId.h" 28 | #include "core/FileActiveStatus.h" 29 | #include "core/SharedMemoryContext.h" 30 | #include "common/Memory.h" 31 | #include "common/Unordered.h" 32 | 33 | namespace Gopherwood { 34 | namespace Internal { 35 | 36 | class ActiveStatusContext { 37 | public: 38 | ActiveStatusContext(shared_ptr sharedMemoryContext); 39 | 40 | shared_ptr createFileActiveStatus(FileId fileId, 41 | bool isWrite, 42 | bool isSequence, 43 | int localSpaceFD 44 | ); 45 | 46 | shared_ptr openFileActiveStatus(FileId fileId, 47 | bool isWrite, 48 | bool isSequence, 49 | int localSpaceFD); 50 | 51 | shared_ptr deleteFileActiveStatus(FileId fileId, int localSpaceFD); 52 | 53 | ~ActiveStatusContext(); 54 | 55 | private: 56 | shared_ptr mSharedMemoryContext; 57 | shared_ptr mThreadPool; 58 | }; 59 | 60 | 61 | } 62 | } 63 | 64 | 65 | #endif //_GOPHERWOOD_CORE_ACTIVESTATUSCONTEXT_H_ 66 | -------------------------------------------------------------------------------- /gtest/include/gtest/gtest_prod.h: -------------------------------------------------------------------------------- 1 | // Copyright 2006, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: wan@google.com (Zhanyong Wan) 31 | // 32 | // Google C++ Testing Framework definitions useful in production code. 33 | 34 | #ifndef GTEST_INCLUDE_GTEST_GTEST_PROD_H_ 35 | #define GTEST_INCLUDE_GTEST_GTEST_PROD_H_ 36 | 37 | // When you need to test the private or protected members of a class, 38 | // use the FRIEND_TEST macro to declare your tests as friends of the 39 | // class. For example: 40 | // 41 | // class MyClass { 42 | // private: 43 | // void MyMethod(); 44 | // FRIEND_TEST(MyClassTest, MyMethod); 45 | // }; 46 | // 47 | // class MyClassTest : public testing::Test { 48 | // // ... 49 | // }; 50 | // 51 | // TEST_F(MyClassTest, MyMethod) { 52 | // // Can call MyClass::MyMethod() here. 53 | // } 54 | 55 | #define FRIEND_TEST(test_case_name, test_name)\ 56 | friend class test_case_name##_##test_name##_Test 57 | 58 | #endif // GTEST_INCLUDE_GTEST_GTEST_PROD_H_ 59 | -------------------------------------------------------------------------------- /src/common/ObjectStorInfo.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * 2017 - 3 | * open source under Apache License Version 2.0 4 | ********************************************************************/ 5 | /** 6 | * Licensed to the Apache Software Foundation (ASF) under one 7 | * or more contributor license agreements. See the NOTICE file 8 | * distributed with this work for additional information 9 | * regarding copyright ownership. The ASF licenses this file 10 | * to you under the Apache License, Version 2.0 (the 11 | * "License"); you may not use this file except in compliance 12 | * with the License. You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | #ifndef GOPHERWOOD_COMMON_OBJECTSTORINFO_H 23 | #define GOPHERWOOD_COMMON_OBJECTSTORINFO_H 24 | 25 | #include "platform.h" 26 | 27 | #include 28 | 29 | namespace Gopherwood { 30 | namespace Internal { 31 | 32 | struct ObjectStorInfo { 33 | std::string object_stor_type; 34 | std::string liboss_access_key_id; 35 | std::string liboss_secret_access_key; 36 | std::string liboss_appid = " "; 37 | std::string liboss_zone; 38 | int64_t liboss_write_buffer = 8 << 20; 39 | int64_t liboss_read_buffer = 32 << 20; 40 | 41 | std::string qs_access_key_id; 42 | std::string qs_secret_access_key; 43 | std::string qs_zone; 44 | int64_t qs_write_buffer = 8 << 20; 45 | int64_t qs_read_buffer = 32 << 20; 46 | 47 | std::string s3_access_key_id; 48 | std::string s3_secret_access_key; 49 | std::string s3_zone; 50 | int64_t s3_write_buffer = 8 << 20; 51 | int64_t s3_read_buffer = 32 << 20; 52 | 53 | std::string txcos_access_key_id; 54 | std::string txcos_secret_access_key; 55 | std::string txcos_appid; 56 | std::string txcos_zone; 57 | int64_t txcos_write_buffer = 8 << 20; 58 | int64_t txcos_read_buffer = 32 << 20; 59 | 60 | std::string alioss_access_key_id; 61 | std::string alioss_secret_access_key; 62 | std::string alioss_zone; 63 | int64_t alioss_write_buffer = 8 << 20; 64 | int64_t alioss_read_buffer = 32 << 20; 65 | }; 66 | 67 | } 68 | } 69 | 70 | #endif //GOPHERWOOD_COMMON_OBJECTSTORINFO_H 71 | -------------------------------------------------------------------------------- /gmock/include/gmock/gmock-more-matchers.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: marcus.boerger@google.com (Marcus Boerger) 31 | 32 | // Google Mock - a framework for writing C++ mock classes. 33 | // 34 | // This file implements some matchers that depend on gmock-generated-matchers.h. 35 | // 36 | // Note that tests are implemented in gmock-matchers_test.cc rather than 37 | // gmock-more-matchers-test.cc. 38 | 39 | #ifndef GMOCK_GMOCK_MORE_MATCHERS_H_ 40 | #define GMOCK_GMOCK_MORE_MATCHERS_H_ 41 | 42 | #include "gmock/gmock-generated-matchers.h" 43 | 44 | namespace testing { 45 | 46 | // Defines a matcher that matches an empty container. The container must 47 | // support both size() and empty(), which all STL-like containers provide. 48 | MATCHER(IsEmpty, negation ? "isn't empty" : "is empty") { 49 | if (arg.empty()) { 50 | return true; 51 | } 52 | *result_listener << "whose size is " << arg.size(); 53 | return false; 54 | } 55 | 56 | } // namespace testing 57 | 58 | #endif // GMOCK_GMOCK_MORE_MATCHERS_H_ 59 | -------------------------------------------------------------------------------- /src/file/FileSystem.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * 2017 - 3 | * open source under Apache License Version 2.0 4 | ********************************************************************/ 5 | /** 6 | * Licensed to the Apache Software Foundation (ASF) under one 7 | * or more contributor license agreements. See the NOTICE file 8 | * distributed with this work for additional information 9 | * regarding copyright ownership. The ASF licenses this file 10 | * to you under the Apache License, Version 2.0 (the 11 | * "License"); you may not use this file except in compliance 12 | * with the License. You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | #ifndef _GOPHERWOOD_CORE_FILESYSTEM_H_ 23 | #define _GOPHERWOOD_CORE_FILESYSTEM_H_ 24 | 25 | #include "platform.h" 26 | 27 | #include "common/Memory.h" 28 | #include "common/Unordered.h" 29 | #include "core/ActiveStatusContext.h" 30 | #include "core/SharedMemoryManager.h" 31 | #include "core/SharedMemoryContext.h" 32 | #include "core/AdminActiveStatus.h" 33 | #include "file/File.h" 34 | #include "oss/oss.h" 35 | 36 | namespace Gopherwood { 37 | namespace Internal { 38 | 39 | class FileSystem { 40 | public: 41 | static void Format(const char *workDir); 42 | 43 | static ossContext OSS_CONTEXT; 44 | 45 | static std::string OSS_BUCKET; 46 | 47 | FileSystem(const char *workDir); 48 | 49 | bool exists(const char *fileName); 50 | 51 | File *CreateFile(const char *fileName, int flags, bool isWrite); 52 | 53 | File *OpenFile(const char *fileName, int flags, bool isWrite); 54 | 55 | void CloseFile(File &file); 56 | 57 | void DeleteFile(const char *fileName); 58 | 59 | void getStatistics(GWSysInfo* sysInfo); 60 | 61 | int32_t preEvictNumOfBlocks(int num); 62 | 63 | ~FileSystem(); 64 | 65 | private: 66 | FileId makeFileId(const std::string filePath); 67 | void initOssContext(); 68 | 69 | int32_t mLocalSpaceFile = -1; 70 | const char *workDir; 71 | shared_ptr mSharedMemoryContext; 72 | shared_ptr mActiveStatusContext; 73 | shared_ptr mAdminActiveStatus; 74 | }; 75 | 76 | } 77 | } 78 | 79 | #endif //_GOPHERWOOD_CORE_FILESYSTEM_H_ 80 | -------------------------------------------------------------------------------- /src/common/Thread.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * 2017 - 3 | * open source under Apache License Version 2.0 4 | ********************************************************************/ 5 | /** 6 | * Licensed to the Apache Software Foundation (ASF) under one 7 | * or more contributor license agreements. See the NOTICE file 8 | * distributed with this work for additional information 9 | * regarding copyright ownership. The ASF licenses this file 10 | * to you under the Apache License, Version 2.0 (the 11 | * "License"); you may not use this file except in compliance 12 | * with the License. You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | #ifndef _GOPHERWOOD_COMMON_THREAD_H_ 23 | #define _GOPHERWOOD_COMMON_THREAD_H_ 24 | 25 | #include "platform.h" 26 | 27 | #include 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | namespace Gopherwood { 36 | namespace Internal { 37 | 38 | using std::thread; 39 | using std::bind; 40 | using std::mutex; 41 | using std::lock_guard; 42 | using std::future; 43 | using std::unique_lock; 44 | using std::condition_variable; 45 | using std::defer_lock_t; 46 | using std::once_flag; 47 | using std::call_once; 48 | using std::function; 49 | using std::result_of; 50 | using std::forward; 51 | using std::packaged_task; 52 | using std::chrono::seconds; 53 | using namespace std::this_thread; 54 | 55 | /* 56 | * make the background thread ignore these signals (which should allow that 57 | * they be delivered to the main thread) 58 | */ 59 | sigset_t ThreadBlockSignal(); 60 | 61 | /* 62 | * Restore previous signals. 63 | */ 64 | void ThreadUnBlockSignal(sigset_t sigs); 65 | 66 | } 67 | } 68 | 69 | #define CREATE_THREAD(retval, fun) \ 70 | do { \ 71 | sigset_t sigs = Gopherwood::Internal::ThreadBlockSignal(); \ 72 | try { \ 73 | retval = Gopherwood::Internal::thread(fun); \ 74 | Gopherwood::Internal::ThreadUnBlockSignal(sigs); \ 75 | } catch (...) { \ 76 | Gopherwood::Internal::ThreadUnBlockSignal(sigs); \ 77 | throw; \ 78 | } \ 79 | } while(0) 80 | 81 | #endif /* _GOPHERWOOD_COMMON_THREAD_H_ */ 82 | -------------------------------------------------------------------------------- /src/common/Hash.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * 2017 - 3 | * open source under Apache License Version 2.0 4 | ********************************************************************/ 5 | /** 6 | * Licensed to the Apache Software Foundation (ASF) under one 7 | * or more contributor license agreements. See the NOTICE file 8 | * distributed with this work for additional information 9 | * regarding copyright ownership. The ASF licenses this file 10 | * to you under the Apache License, Version 2.0 (the 11 | * "License"); you may not use this file except in compliance 12 | * with the License. You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | #include "Hash.h" 23 | 24 | #ifdef NEED_BOOST 25 | 26 | #include 27 | 28 | namespace Gopherwood { 29 | namespace Internal { 30 | 31 | /** 32 | * A hash function object used to hash a boolean value. 33 | */ 34 | boost::hash BoolHasher; 35 | 36 | /** 37 | * A hash function object used to hash an int value. 38 | */ 39 | boost::hash Int32Hasher; 40 | 41 | /** 42 | * A hash function object used to hash an 64 bit int value. 43 | */ 44 | boost::hash Int64Hasher; 45 | 46 | /** 47 | * A hash function object used to hash a size_t value. 48 | */ 49 | boost::hash SizeHasher; 50 | 51 | /** 52 | * A hash function object used to hash a std::string object. 53 | */ 54 | boost::hash StringHasher; 55 | } 56 | } 57 | 58 | #else 59 | 60 | #include 61 | 62 | namespace Gopherwood { 63 | namespace Internal { 64 | 65 | /** 66 | * A hash function object used to hash a boolean value. 67 | */ 68 | std::hash BoolHasher; 69 | 70 | /** 71 | * A hash function object used to hash an int value. 72 | */ 73 | std::hash Int32Hasher; 74 | 75 | /** 76 | * A hash function object used to hash an 64 bit int value. 77 | */ 78 | std::hash Int64Hasher; 79 | 80 | /** 81 | * A hash function object used to hash a size_t value. 82 | */ 83 | std::hash SizeHasher; 84 | 85 | /** 86 | * A hash function object used to hash a std::string object. 87 | */ 88 | std::hash StringHasher; 89 | 90 | } 91 | } 92 | 93 | #endif 94 | -------------------------------------------------------------------------------- /src/block/BlockInputStream.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * 2017 - 3 | * open source under Apache License Version 2.0 4 | ********************************************************************/ 5 | /** 6 | * Licensed to the Apache Software Foundation (ASF) under one 7 | * or more contributor license agreements. See the NOTICE file 8 | * distributed with this work for additional information 9 | * regarding copyright ownership. The ASF licenses this file 10 | * to you under the Apache License, Version 2.0 (the 11 | * "License"); you may not use this file except in compliance 12 | * with the License. You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | #include "block/BlockInputStream.h" 23 | #include "common/Configuration.h" 24 | #include "common/Logger.h" 25 | #include "file/FileSystem.h" 26 | 27 | namespace Gopherwood { 28 | namespace Internal { 29 | 30 | BlockInputStream::BlockInputStream(int fd) : mLocalSpaceFD(fd) { 31 | mLocalReader = shared_ptr(new LocalBlockReader(fd)); 32 | mOssWorker = shared_ptr(new OssBlockWorker(FileSystem::OSS_CONTEXT, fd)); 33 | mBucketSize = Configuration::LOCAL_BUCKET_SIZE; 34 | } 35 | 36 | void BlockInputStream::setBlockInfo(BlockInfo info) { 37 | LOG(DEBUG1, "[BlockInputStream] |" 38 | "Set BlockInfo, new bucketId=%d, new blockOffset=%ld, %s", 39 | info.bucketId, info.offset, info.isLocal ? "local" : "remote"); 40 | mBlockInfo = info; 41 | } 42 | 43 | int64_t BlockInputStream::remaining() { 44 | return mBucketSize - mBlockInfo.offset; 45 | } 46 | 47 | int64_t BlockInputStream::read(char *buffer, int64_t length) { 48 | int64_t read = -1; 49 | 50 | if (mBlockInfo.isLocal) { 51 | mLocalReader->seek(getLocalSpaceOffset()); 52 | read = mLocalReader->readLocal(buffer, length); 53 | LOG(DEBUG1, "[BlockInputStream] |" 54 | "Read from local space, bucketId=%d, offset=%ld, length=%ld", 55 | mBlockInfo.bucketId, mBlockInfo.offset, length); 56 | } else { 57 | /* Read from OSS */ 58 | } 59 | 60 | mBlockInfo.offset += read; 61 | assert(mBlockInfo.offset <= mBucketSize); 62 | 63 | return read; 64 | } 65 | 66 | void BlockInputStream::flush() { 67 | 68 | } 69 | 70 | int64_t BlockInputStream::getLocalSpaceOffset() { 71 | return mBlockInfo.bucketId * mBucketSize + mBlockInfo.offset; 72 | } 73 | 74 | BlockInputStream::~BlockInputStream() { 75 | 76 | } 77 | 78 | } 79 | } -------------------------------------------------------------------------------- /src/file/InputStream.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * 2017 - 3 | * open source under Apache License Version 2.0 4 | ********************************************************************/ 5 | /** 6 | * Licensed to the Apache Software Foundation (ASF) under one 7 | * or more contributor license agreements. See the NOTICE file 8 | * distributed with this work for additional information 9 | * regarding copyright ownership. The ASF licenses this file 10 | * to you under the Apache License, Version 2.0 (the 11 | * "License"); you may not use this file except in compliance 12 | * with the License. You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | #include "file/InputStream.h" 23 | 24 | namespace Gopherwood { 25 | namespace Internal { 26 | 27 | InputStream::InputStream(int fd, shared_ptr status) : 28 | mLocalSpaceFD(fd), mStatus(status) { 29 | mPos = 0; 30 | mBlockInputStream = shared_ptr(new BlockInputStream(mLocalSpaceFD)); 31 | } 32 | 33 | void InputStream::updateBlockStream() { 34 | /* TODO: Implement this once we make BlockOutput stream a buffered stream */ 35 | mBlockInputStream->flush(); 36 | 37 | /* Update the BlockInfo of the BlockOutputStream */ 38 | mBlockInputStream->setBlockInfo(mStatus->getCurBlockInfo()); 39 | 40 | /* Update the position*/ 41 | mPos = mStatus->getPosition(); 42 | } 43 | 44 | void InputStream::read(char *buffer, int64_t length) { 45 | int64_t bytesToRead = length; 46 | int64_t bytesRead = 0; 47 | bool needUpdate = true; 48 | 49 | /* write the buffer, switch target block if needed */ 50 | while (bytesToRead > 0) { 51 | /* update BlockOutputStream, flush previous cached data 52 | * and switch to target block id & offset */ 53 | if (needUpdate) { 54 | updateBlockStream(); 55 | needUpdate = false; 56 | } 57 | 58 | /* write to target block */ 59 | int64_t read; 60 | if (bytesToRead <= mBlockInputStream->remaining()) { 61 | read = mBlockInputStream->read(buffer + bytesRead, bytesToRead); 62 | } else { 63 | read = mBlockInputStream->read(buffer + bytesRead, mBlockInputStream->remaining()); 64 | needUpdate = true; 65 | } 66 | 67 | /* update statistics */ 68 | bytesToRead -= read; 69 | bytesRead += read; 70 | mPos += read; 71 | mStatus->setPosition(mPos); 72 | } 73 | } 74 | 75 | void InputStream::close() { 76 | 77 | } 78 | 79 | InputStream::~InputStream() { 80 | 81 | } 82 | 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /mock/TestUtil.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * 2016 - 3 | * open source under Apache License Version 2.0 4 | ********************************************************************/ 5 | /** 6 | * Licensed to the Apache Software Foundation (ASF) under one 7 | * or more contributor license agreements. See the NOTICE file 8 | * distributed with this work for additional information 9 | * regarding copyright ownership. The ASF licenses this file 10 | * to you under the Apache License, Version 2.0 (the 11 | * "License"); you may not use this file except in compliance 12 | * with the License. You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | #ifndef _GOPHERWOOD_MOCK_TESTUTIL_H_ 23 | #define _GOPHERWOOD_MOCK_TESTUTIL_H_ 24 | 25 | #include 26 | #include 27 | 28 | #include "Logger.h" 29 | 30 | namespace Gopherwood { 31 | 32 | /** 33 | * Fill the buffer with "012345678\n". 34 | * @param buffer The buffer to be filled. 35 | * @param size The size of the buffer. 36 | * @param offset Start offset of the content to be filled. 37 | */ 38 | static inline void FillBuffer(char * buffer, size_t size, size_t offset) { 39 | int64_t todo = size; 40 | 41 | char c; 42 | while (todo-- > 0) { 43 | c = offset++ % 10; 44 | c = c < 9 ? c + '0' : '\n'; 45 | *buffer++ = c; 46 | } 47 | } 48 | 49 | /** 50 | * Check the content of buffer if it is filled with "012345678\n" 51 | * @param buffer The buffer to be checked. 52 | * @param size The size of buffer. 53 | * @param offset Start offset of the content in buffer. 54 | * @return Return true if the content of buffer is filled with expected data. 55 | */ 56 | static inline bool CheckBuffer(const char * buffer, size_t size, 57 | size_t offset) { 58 | int64_t todo = size; 59 | 60 | char c; 61 | while (todo-- > 0) { 62 | c = offset++ % 10; 63 | c = c < 9 ? c + '0' : '\n'; 64 | if (*buffer++ != c) { 65 | return false; 66 | } 67 | } 68 | 69 | return true; 70 | } 71 | 72 | static inline const char * GetEnv(const char * key, const char * defaultValue) { 73 | const char * retval = getenv(key); 74 | if (retval && strlen(retval) > 0) { 75 | return retval; 76 | } 77 | return defaultValue; 78 | } 79 | 80 | } 81 | 82 | #define DebugException(function) \ 83 | try { \ 84 | function ; \ 85 | } catch (const Gopherwood::GopherwoodException & e) { \ 86 | std::string buffer; \ 87 | LOG(LOG_ERROR, "DEBUG:\n%s", Gopherwood::Internal::GetExceptionDetail(e, buffer)); \ 88 | throw; \ 89 | } catch (const std::exception & e) { \ 90 | LOG(LOG_ERROR, "DEBUG:\n%s", e.what()); \ 91 | throw; \ 92 | } 93 | 94 | #endif 95 | -------------------------------------------------------------------------------- /test/function/TapeSort/src/dbtproj.h: -------------------------------------------------------------------------------- 1 | /* 2 | * DBMS Implementation 3 | * Copyright (C) 2013 George Piskas, George Economides 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | * 19 | * Contact: geopiskas@gmail.com 20 | */ 21 | 22 | /* 23 | * ========================================================================================== 24 | * Database Technology 2012-2013 25 | * Header file dbtproj.h to be used by your code. 26 | * It is not permitted to change this file. You can make changes to perform tests, 27 | * but please rely on the values and typedefs shown below. 28 | * 29 | * ========================================================================================== 30 | * 31 | */ 32 | 33 | 34 | #ifndef _DBTPROJ_H 35 | #define _DBTPROJ_H 36 | 37 | #include 38 | #include 39 | 40 | #define STR_LENGTH 32 41 | #define MAX_RECORDS_PER_BLOCK 5000 42 | 43 | #define BLOCK_SIZE 64*1024*1024 44 | #define NUMBER_OF_BLOCKS 190 45 | #define NUM_CONCURRENCY 4 46 | #define SEVERITY 2 47 | #define FILE_NAME "/home/ec2-user/datas/catalog_sales.dat" 48 | 49 | 50 | #define WORK_DIR "/media/ephemeral0/goworkspace" 51 | // This is the definition of a record. Contains three fields, recid, num and str 52 | 53 | 54 | 55 | 56 | typedef struct { 57 | int recid; 58 | bool valid; // if set, then this block is valid 59 | char cs_sold_date_sk[STR_LENGTH]; 60 | char cs_sold_time_sk[STR_LENGTH]; 61 | char cs_ship_date_sk[STR_LENGTH]; 62 | char cs_item_sk[STR_LENGTH]; 63 | char cs_quantity[STR_LENGTH]; 64 | } record_t; 65 | 66 | 67 | // This is the definition of a block, which contains a number of fixed-sized records 68 | 69 | typedef struct { 70 | unsigned int blockid; 71 | unsigned int nreserved; // how many reserved entries 72 | record_t entries[MAX_RECORDS_PER_BLOCK]; // array of records 73 | bool valid; // if set, then this block is valid 74 | unsigned char misc; 75 | unsigned int next_blockid; 76 | unsigned int dummy; 77 | } block_t; 78 | 79 | 80 | class dbtproj { 81 | public: 82 | 83 | static int64_t totalReadTime; 84 | 85 | void MergeSort(char *infile, unsigned char field, block_t *buffer, unsigned int nmem_blocks, char *outfile, 86 | unsigned int *nsorted_segs, unsigned int *npasses, unsigned int *nios); 87 | 88 | std::string getTimeMergeSort(); 89 | 90 | }; 91 | 92 | #endif 93 | -------------------------------------------------------------------------------- /test/function/TestCInterface.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * 2016 - 3 | * open source under Apache License Version 2.0 4 | ********************************************************************/ 5 | /** 6 | * Licensed to the Apache Software Foundation (ASF) under one 7 | * or more contributor license agreements. See the NOTICE file 8 | * distributed with this work for additional information 9 | * regarding copyright ownership. The ASF licenses this file 10 | * to you under the Apache License, Version 2.0 (the 11 | * "License"); you may not use this file except in compliance 12 | * with the License. You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | #include "client/gopherwood.h" 23 | #include "common/DateTime.h" 24 | #include "common/Exception.h" 25 | #include "common/ExceptionInternal.h" 26 | #include "gtest/gtest.h" 27 | 28 | using namespace Gopherwood; 29 | using namespace Gopherwood::Internal; 30 | 31 | class TestCInterface: public ::testing::Test { 32 | public: 33 | TestCInterface() 34 | { 35 | try { 36 | sprintf(workDir, "/data/gopherwood"); 37 | 38 | GWContextConfig config; 39 | config.blockSize = 10; 40 | config.numBlocks = 50; 41 | config.numPreDefinedConcurrency = 10; 42 | config.severity = LOGSEV_INFO; 43 | fs = gwCreateContext(workDir, &config); 44 | } catch (...) { 45 | 46 | } 47 | } 48 | 49 | ~TestCInterface() { 50 | try { 51 | gwDestroyContext(fs); 52 | } catch (...) { 53 | } 54 | } 55 | 56 | protected: 57 | char workDir[40]; 58 | gopherwoodFS fs; 59 | 60 | }; 61 | 62 | TEST_F(TestCInterface, TestFormatContext) { 63 | ASSERT_NO_THROW(gwFormatContext(workDir)); 64 | } 65 | 66 | TEST_F(TestCInterface, TestCancel_Success) { 67 | char fileName[] = "TestCInterface/TestCancel_Success"; 68 | char input[] = "0123456789"; 69 | 70 | gwFile file = NULL; 71 | int len; 72 | 73 | ASSERT_NO_THROW(file = gwOpenFile(fs, fileName, GW_CREAT|GW_RDWR)); 74 | for (int i=0; i<5; i++) { 75 | ASSERT_NO_THROW(len = gwWrite(fs, file, input, 10)); 76 | EXPECT_EQ(10, len); 77 | } 78 | 79 | ASSERT_NO_THROW(gwCancelFile(fs, file)); 80 | EXPECT_FALSE(gwFileExists(fs, fileName)); 81 | } 82 | 83 | TEST_F(TestCInterface, TestOpen_Fail_OpenSecondWrite) { 84 | // char fileName[] = "TestCInterface/TestCancel_Success"; 85 | // char input[] = "0123456789"; 86 | // 87 | // gwFile file = NULL; 88 | // gwFile file1 = NULL; 89 | // int len; 90 | // 91 | // ASSERT_NO_THROW(file = gwOpenFile(fs, fileName, GW_CREAT|GW_RDWR)); 92 | // ASSERT_THROW(file1 = gwOpenFile(fs, fileName, GW_CREAT|GW_RDWR), GopherwoodOSSException); 93 | // 94 | // 95 | // ASSERT_NO_THROW(gwCancelFile(fs, file)); 96 | } 97 | 98 | 99 | -------------------------------------------------------------------------------- /src/block/BlockOutputStream.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * 2017 - 3 | * open source under Apache License Version 2.0 4 | ********************************************************************/ 5 | /** 6 | * Licensed to the Apache Software Foundation (ASF) under one 7 | * or more contributor license agreements. See the NOTICE file 8 | * distributed with this work for additional information 9 | * regarding copyright ownership. The ASF licenses this file 10 | * to you under the Apache License, Version 2.0 (the 11 | * "License"); you may not use this file except in compliance 12 | * with the License. You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | #include "block/BlockOutputStream.h" 23 | #include "common/Exception.h" 24 | #include "common/ExceptionInternal.h" 25 | #include "common/Configuration.h" 26 | #include "common/Logger.h" 27 | #include "file/FileSystem.h" 28 | 29 | namespace Gopherwood { 30 | namespace Internal { 31 | 32 | BlockOutputStream::BlockOutputStream(int fd) : mLocalSpaceFD(fd) { 33 | mLocalWriter = shared_ptr(new LocalBlockWriter(fd)); 34 | mOssWorker = shared_ptr(new OssBlockWorker(FileSystem::OSS_CONTEXT, fd)); 35 | mBucketSize = Configuration::LOCAL_BUCKET_SIZE; 36 | mBlockInfo.reset(); 37 | mCached = false; 38 | } 39 | 40 | void BlockOutputStream::setBlockInfo(BlockInfo info) { 41 | LOG(DEBUG1, "[BlockOutputStream] |" 42 | "Set BlockInfo bucketId=%d, new blockOffset=%ld, %s", 43 | info.bucketId, info.offset, info.isLocal ? "local" : "remote"); 44 | mBlockInfo = info; 45 | } 46 | 47 | int64_t BlockOutputStream::remaining() { 48 | return mBucketSize - mBlockInfo.offset; 49 | } 50 | 51 | int64_t BlockOutputStream::write(const char *buffer, int64_t length) { 52 | int64_t written = -1; 53 | 54 | if (mBlockInfo.isLocal) { 55 | mLocalWriter->seek(getLocalSpaceOffset()); 56 | LOG(DEBUG1, "[BlockOutputStream] |" 57 | "Write to local space, bucketId=%d, offset=%ld, length=%ld", 58 | mBlockInfo.bucketId, mBlockInfo.offset, length); 59 | written = mLocalWriter->writeLocal(buffer, length); 60 | } else { 61 | /* Write to OSS */ 62 | } 63 | 64 | mCached = true; 65 | 66 | mBlockInfo.offset += written; 67 | assert(mBlockInfo.offset <= mBucketSize); 68 | 69 | return written; 70 | } 71 | 72 | void BlockOutputStream::flush() { 73 | if (!mCached){ 74 | return; 75 | } 76 | 77 | if (mBlockInfo.isLocal) { 78 | mLocalWriter->flush(); 79 | } else { 80 | /* TODO: Remote flush, currently we won't write to OSS directly */ 81 | } 82 | } 83 | 84 | int64_t BlockOutputStream::getLocalSpaceOffset() { 85 | return mBlockInfo.bucketId * mBucketSize + mBlockInfo.offset; 86 | } 87 | 88 | BlockOutputStream::~BlockOutputStream() { 89 | 90 | } 91 | 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/common/ThreadPool.h: -------------------------------------------------------------------------------- 1 | #ifndef _GOPHERWOOD_COMMON_THREAD_POOL_H 2 | #define _GOPHERWOOD_COMMON_THREAD_POOL_H 3 | 4 | #include "common/Thread.h" 5 | #include "common/Exception.h" 6 | #include "common/ExceptionInternal.h" 7 | #include "common/Logger.h" 8 | #include 9 | #include 10 | 11 | namespace Gopherwood { 12 | namespace Internal { 13 | 14 | class ThreadPool { 15 | public: 16 | ThreadPool(size_t); 17 | 18 | template 19 | auto enqueue(F &&f, Args &&... args) -> future::type>; 20 | 21 | ~ThreadPool(); 22 | 23 | private: 24 | // need to keep track of threads so we can join them 25 | std::vector workers; 26 | // the task queue 27 | std::queue > tasks; 28 | 29 | // synchronization 30 | mutex queue_mutex; 31 | condition_variable condition; 32 | bool stop; 33 | }; 34 | 35 | // the constructor just launches some amount of workers 36 | inline ThreadPool::ThreadPool(size_t threads) 37 | : stop(false) { 38 | sigset_t sigs = ThreadBlockSignal(); 39 | try { 40 | for (size_t i = 0; i < threads; ++i) 41 | workers.emplace_back( 42 | [this] { 43 | for (;;) { 44 | function task; 45 | 46 | { 47 | unique_lock lock(this->queue_mutex); 48 | this->condition.wait(lock, 49 | [this] { return this->stop || !this->tasks.empty(); }); 50 | if (this->stop && this->tasks.empty()) 51 | return; 52 | task = move(this->tasks.front()); 53 | this->tasks.pop(); 54 | } 55 | 56 | task(); 57 | } 58 | } 59 | ); 60 | ThreadUnBlockSignal(sigs); 61 | } catch (...) { 62 | ThreadUnBlockSignal(sigs); 63 | throw; 64 | } 65 | } 66 | 67 | // add new work item to the pool 68 | template 69 | auto ThreadPool::enqueue(F &&f, Args &&... args) 70 | -> future::type> { 71 | using return_type = typename result_of::type; 72 | 73 | auto task = make_shared >( 74 | bind(forward(f), forward(args)...) 75 | ); 76 | 77 | future res = task->get_future(); 78 | { 79 | unique_lock lock(queue_mutex); 80 | 81 | // don't allow enqueueing after stopping the pool 82 | if (stop) 83 | THROW(GopherwoodIOException, 84 | "[ThreadPool::enqueue] enqueuing on stopped ThreadPool"); 85 | 86 | tasks.emplace([task]() { (*task)(); }); 87 | } 88 | condition.notify_one(); 89 | return res; 90 | } 91 | 92 | // the destructor joins all threads 93 | inline ThreadPool::~ThreadPool() { 94 | { 95 | unique_lock lock(queue_mutex); 96 | stop = true; 97 | } 98 | condition.notify_all(); 99 | for (thread &worker: workers) 100 | worker.join(); 101 | } 102 | 103 | } 104 | } 105 | #endif -------------------------------------------------------------------------------- /test/function/HashJoin/src/recordPtr.h: -------------------------------------------------------------------------------- 1 | /* 2 | * DBMS Implementation 3 | * Copyright (C) 2013 George Piskas, George Economides 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | * 19 | * Contact: geopiskas@gmail.com 20 | */ 21 | 22 | #ifndef RECORDPTR_H 23 | #define RECORDPTR_H 24 | 25 | #include 26 | 27 | #include "dbtproj.h" 28 | 29 | // location of a specific record in the buffer 30 | // block is the index number of the block the record is in 31 | // record is the index number of the record in the entries table 32 | 33 | typedef struct { 34 | uint block; 35 | int record; 36 | } recordPtr; 37 | 38 | // struct for making linked lists of recordPtrs 39 | 40 | struct linkedRecordPtr { 41 | recordPtr ptr; 42 | linkedRecordPtr *next; 43 | }; 44 | 45 | // overloading of some operators so that comparisons can be made 46 | // between two recordPtr variables 47 | bool operator==(const recordPtr &ptr1, const recordPtr &ptr2); 48 | 49 | bool operator!=(const recordPtr &ptr1, const recordPtr &ptr2); 50 | 51 | bool operator>(const recordPtr &ptr1, const recordPtr &ptr2); 52 | 53 | bool operator<(const recordPtr &ptr1, const recordPtr &ptr2); 54 | 55 | bool operator>=(const recordPtr &ptr1, const recordPtr &ptr2); 56 | 57 | bool operator<=(const recordPtr &ptr1, const recordPtr &ptr2); 58 | 59 | uint operator-(const recordPtr &ptr1, const recordPtr &ptr2); 60 | 61 | recordPtr operator+(const recordPtr &ptr, int offset); 62 | 63 | recordPtr operator-(const recordPtr &ptr, int offset); 64 | 65 | inline recordPtr copyPtr(recordPtr ptr) { 66 | return ptr + 0; 67 | } 68 | 69 | inline recordPtr newPtr(recordPtr ptr, uint offset) { 70 | return ptr + offset; 71 | } 72 | 73 | inline recordPtr newPtr(uint offset) { 74 | recordPtr zero; 75 | zero.block = 0; 76 | zero.record = 0; 77 | return zero + offset; 78 | } 79 | 80 | inline uint getOffset(recordPtr ptr) { 81 | return ptr - newPtr(0); 82 | } 83 | 84 | // increases the ptr so that it points to the next record 85 | // if pointing at the end of a block, moves to the start of the next 86 | 87 | inline void incr(recordPtr &ptr) { 88 | if (ptr.record < MAX_RECORDS_PER_BLOCK - 1) { 89 | ptr.record += 1; 90 | } else { 91 | ptr.record = 0; 92 | ptr.block += 1; 93 | } 94 | } 95 | 96 | // decreases the ptr so that it points to the next record 97 | // if pointing at the start of a block, moves to the end of the previous 98 | 99 | inline void decr(recordPtr &ptr) { 100 | if (ptr.record > 0) { 101 | ptr.record -= 1; 102 | } else if (ptr.block > 0) { 103 | ptr.record = MAX_RECORDS_PER_BLOCK - 1; 104 | ptr.block -= 1; 105 | } 106 | } 107 | 108 | #endif -------------------------------------------------------------------------------- /test/function/TapeSort/src/recordPtr.h: -------------------------------------------------------------------------------- 1 | /* 2 | * DBMS Implementation 3 | * Copyright (C) 2013 George Piskas, George Economides 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | * 19 | * Contact: geopiskas@gmail.com 20 | */ 21 | 22 | #ifndef RECORDPTR_H 23 | #define RECORDPTR_H 24 | 25 | #include 26 | 27 | #include "dbtproj.h" 28 | 29 | // location of a specific record in the buffer 30 | // block is the index number of the block the record is in 31 | // record is the index number of the record in the entries table 32 | 33 | typedef struct { 34 | uint block; 35 | int record; 36 | } recordPtr; 37 | 38 | // struct for making linked lists of recordPtrs 39 | 40 | struct linkedRecordPtr { 41 | recordPtr ptr; 42 | linkedRecordPtr *next; 43 | }; 44 | 45 | // overloading of some operators so that comparisons can be made 46 | // between two recordPtr variables 47 | bool operator==(const recordPtr &ptr1, const recordPtr &ptr2); 48 | 49 | bool operator!=(const recordPtr &ptr1, const recordPtr &ptr2); 50 | 51 | bool operator>(const recordPtr &ptr1, const recordPtr &ptr2); 52 | 53 | bool operator<(const recordPtr &ptr1, const recordPtr &ptr2); 54 | 55 | bool operator>=(const recordPtr &ptr1, const recordPtr &ptr2); 56 | 57 | bool operator<=(const recordPtr &ptr1, const recordPtr &ptr2); 58 | 59 | uint operator-(const recordPtr &ptr1, const recordPtr &ptr2); 60 | 61 | recordPtr operator+(const recordPtr &ptr, int offset); 62 | 63 | recordPtr operator-(const recordPtr &ptr, int offset); 64 | 65 | inline recordPtr copyPtr(recordPtr ptr) { 66 | return ptr + 0; 67 | } 68 | 69 | inline recordPtr newPtr(recordPtr ptr, uint offset) { 70 | return ptr + offset; 71 | } 72 | 73 | inline recordPtr newPtr(uint offset) { 74 | recordPtr zero; 75 | zero.block = 0; 76 | zero.record = 0; 77 | return zero + offset; 78 | } 79 | 80 | inline uint getOffset(recordPtr ptr) { 81 | return ptr - newPtr(0); 82 | } 83 | 84 | // increases the ptr so that it points to the next record 85 | // if pointing at the end of a block, moves to the start of the next 86 | 87 | inline void incr(recordPtr &ptr) { 88 | if (ptr.record < MAX_RECORDS_PER_BLOCK - 1) { 89 | ptr.record += 1; 90 | } else { 91 | ptr.record = 0; 92 | ptr.block += 1; 93 | } 94 | } 95 | 96 | // decreases the ptr so that it points to the next record 97 | // if pointing at the start of a block, moves to the end of the previous 98 | 99 | inline void decr(recordPtr &ptr) { 100 | if (ptr.record > 0) { 101 | ptr.record -= 1; 102 | } else if (ptr.block > 0) { 103 | ptr.record = MAX_RECORDS_PER_BLOCK - 1; 104 | ptr.block -= 1; 105 | } 106 | } 107 | 108 | #endif -------------------------------------------------------------------------------- /src/core/BlockStatus.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * 2017 - 3 | * open source under Apache License Version 2.0 4 | ********************************************************************/ 5 | /** 6 | * Licensed to the Apache Software Foundation (ASF) under one 7 | * or more contributor license agreements. See the NOTICE file 8 | * distributed with this work for additional information 9 | * regarding copyright ownership. The ASF licenses this file 10 | * to you under the Apache License, Version 2.0 (the 11 | * "License"); you may not use this file except in compliance 12 | * with the License. You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | #include "common/Exception.h" 23 | #include "common/ExceptionInternal.h" 24 | #include "core/BlockStatus.h" 25 | #include "SharedMemoryContext.h" 26 | 27 | namespace Gopherwood { 28 | namespace Internal { 29 | 30 | Block::Block(int32_t theBucketId, int32_t theBlockId, bool local, uint8_t s) : 31 | bucketId(theBucketId), 32 | blockId(theBlockId), 33 | isLocal(local), 34 | state(s), 35 | usageCount(0) { 36 | } 37 | 38 | std::string Block::toLogFormat() { 39 | std::string res(""); 40 | BlockRecord record; 41 | 42 | /* build flags */ 43 | record.rFlags = 0; 44 | if (isLocal == RemoteBlock) { 45 | record.rFlags |= BLOCK_RECORD_REMOTE; 46 | } 47 | switch (state) { 48 | /* No need to set bucket status free, since it's 0 */ 49 | case BUCKET_FREE: 50 | record.rFlags |= BLOCK_RECORD_FREE; 51 | break; 52 | case BUCKET_ACTIVE: 53 | record.rFlags |= BLOCK_RECORD_ACTIVE; 54 | break; 55 | case BUCKET_USED: 56 | record.rFlags |= BLOCK_RECORD_USED; 57 | break; 58 | default: 59 | THROW(GopherwoodException, 60 | "[Block::toLogFormat] Unrecognized BlockState %d", 61 | state); 62 | } 63 | 64 | record.rBucketId = bucketId; 65 | record.rBlockId = blockId; 66 | 67 | char buf[sizeof(BlockRecord)]; 68 | memcpy(buf, &record, sizeof(BlockRecord)); 69 | res.append(buf, sizeof(buf)); 70 | 71 | return res; 72 | } 73 | 74 | Block BlockRecord::toBlockFormat() { 75 | uint8_t state = BUCKET_FREE; 76 | 77 | bool isLocal = rFlags & BLOCK_RECORD_REMOTE ? RemoteBlock : LocalBlock; 78 | int type = rFlags & BLOCK_RECORD_TYPE_MASK; 79 | 80 | switch (type) { 81 | case BLOCK_RECORD_FREE: 82 | state = BUCKET_FREE; 83 | break; 84 | case BLOCK_RECORD_ACTIVE: 85 | state = BUCKET_ACTIVE; 86 | break; 87 | case BLOCK_RECORD_USED: 88 | state = BUCKET_USED; 89 | break; 90 | default: 91 | THROW(GopherwoodException, 92 | "[Block::toBlockFormat] Unrecognized BlockRecordState %d", 93 | state); 94 | } 95 | 96 | return Block(rBucketId, rBlockId, isLocal, state); 97 | } 98 | 99 | } 100 | } -------------------------------------------------------------------------------- /src/core/BlockStatus.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * 2017 - 3 | * open source under Apache License Version 2.0 4 | ********************************************************************/ 5 | /** 6 | * Licensed to the Apache Software Foundation (ASF) under one 7 | * or more contributor license agreements. See the NOTICE file 8 | * distributed with this work for additional information 9 | * regarding copyright ownership. The ASF licenses this file 10 | * to you under the Apache License, Version 2.0 (the 11 | * "License"); you may not use this file except in compliance 12 | * with the License. You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | #ifndef GOPHERWOOD_BLOCKSTATUS_H 23 | #define GOPHERWOOD_BLOCKSTATUS_H 24 | 25 | #include "platform.h" 26 | #include "common/Memory.h" 27 | #include "file/FileId.h" 28 | 29 | namespace Gopherwood { 30 | namespace Internal { 31 | 32 | #define InvalidBucketId -1 33 | #define InvalidBlockId -1 34 | #define LocalBlock true 35 | #define RemoteBlock false 36 | 37 | #define LOAD_INIT 0 38 | #define LOAD_START 1 39 | #define LOAD_FINISHED 2 40 | #define LOAD_ERROR 3 41 | 42 | /* The in-memory file block info */ 43 | typedef struct Block { 44 | /* The bucket id in local cache space */ 45 | int32_t bucketId; 46 | /* The block id of Gopherwood File */ 47 | int32_t blockId; 48 | /* Ture if current block is in OSS */ 49 | bool isLocal; 50 | /* Current bucket status of this block, only 51 | * meaningful when block is in local cache space */ 52 | uint8_t state; 53 | /* The usage count during the activate status */ 54 | int16_t usageCount; 55 | 56 | Block(int32_t theBucketId, int32_t theBlockId, bool local, uint8_t s); 57 | 58 | std::string toLogFormat(); 59 | } Block; 60 | 61 | #define BLOCK_RECORD_REMOTE 0x8000 62 | 63 | #define BLOCK_RECORD_TYPE_MASK 0x0003 64 | #define BLOCK_RECORD_FREE 0x0000 65 | #define BLOCK_RECORD_ACTIVE 0x0001 66 | #define BLOCK_RECORD_USED 0x0002 67 | 68 | /* The Block info for Manifest Log format */ 69 | typedef struct BlockRecord { 70 | /* Compact format of block status 71 | * 0~1 bits: Bucket type if the block is in local cache space 72 | * 15 bit : Mark the block is in OSS or in local cache space*/ 73 | uint16_t rFlags; 74 | uint16_t rPadding; 75 | /* The bucket id in local cache space */ 76 | int32_t rBucketId; 77 | /* The block id of Gopherwood File */ 78 | int32_t rBlockId; 79 | 80 | Block toBlockFormat(); 81 | } BlockRecord; 82 | 83 | #define InvalidBlockOffset -1 84 | 85 | typedef struct BlockInfo { 86 | FileId fileId; 87 | int32_t blockId; 88 | int32_t bucketId; 89 | int64_t offset; 90 | int64_t dataSize; 91 | bool isLocal; 92 | 93 | void reset(){ 94 | fileId.reset(); 95 | blockId = InvalidBlockId; 96 | bucketId = InvalidBucketId; 97 | offset = InvalidBlockOffset; 98 | dataSize = 0; 99 | } 100 | } BlockInfo; 101 | 102 | } 103 | } 104 | #endif //GOPHERWOOD_BLOCKSTATUS_H 105 | -------------------------------------------------------------------------------- /bootstrap: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | die() { 4 | echo "$@" 1>&2 ; exit 1 5 | } 6 | 7 | arg () { 8 | echo "$1" | sed "s/^${2-[^=]*=}//" | sed "s/:/;/g" 9 | } 10 | 11 | # Detect directory information. 12 | source_dir=`cd "\`dirname \"$0\"\`";pwd` 13 | binary_dir=`pwd` 14 | 15 | # Choose the default install prefix. 16 | default_prefix=${source_dir}/dist 17 | 18 | # Choose the default dependency install prefix 19 | default_dependency=${DEPENDENCY_INSTALL_PREFIX} 20 | 21 | if [ x"${default_dependency}" = x"" ]; then 22 | default_dependency="/opt/dependency" 23 | fi 24 | 25 | # Display bootstrap usage 26 | usage() { 27 | echo ' 28 | Usage: '"$0"' [] 29 | Options: [defaults in brackets after descriptions] 30 | Configuration: 31 | --help print this message 32 | --prefix=PREFIX install files in tree rooted at PREFIX 33 | ['"${default_prefix}"'] 34 | --dependency=DIRs specify the dependencies at DIRs, separated by colon 35 | ['"${default_dependency}"'] 36 | --enable-debug enable debug build 37 | --enable-boost force to enable boost 38 | --enable-coverage enable build with code coverage support 39 | --enable-libc++ using libc++ instead of libstdc++, only valid for clang compiler 40 | 41 | Dependencies: 42 | c/c++ compiler 43 | GNU make 44 | cmake http://www.cmake.org/ 45 | boost 1.53+ http://www.boost.org/ 46 | [boost is not required if c++ compiler is g++ 4.6.0+ or clang++ with stdc++] 47 | 48 | Example: 49 | mkdir build 50 | cd build 51 | ../bootstrap --prefix=/path/to/install --dependency=/path/to/thrift:/path/to/protobuf:/path/to/kerberos/:path/to/others 52 | make 53 | make install 54 | ' 55 | exit 10 56 | } 57 | 58 | # Parse arguments 59 | prefix_dirs="${default_prefix}" 60 | dependency_dir="${default_dependency}" 61 | build_type="Release" 62 | enable_boost="ON" 63 | enable_coverage="OFF" 64 | enable_clang_lib="OFF" 65 | while test $# != 0; do 66 | case "$1" in 67 | --prefix=*) dir=`arg "$1"` 68 | prefix_dirs="$dir";; 69 | --dependency=*) dir=`arg "$1"` 70 | dependency_dir="$dir";; 71 | --enable-debug) enable_build="ON";; 72 | --enable-coverage) enable_coverage="ON";; 73 | --enable-libc++) enable_clang_lib="ON";; 74 | --help) usage ;; 75 | *) die "Unknown option: $1" ;; 76 | esac 77 | shift 78 | done 79 | 80 | if [ ${source_dir} = ${binary_dir} ]; then 81 | die "cannot build the project in the source directory! Out-of-source build is enforced!" 82 | fi 83 | 84 | # Check clang compiler 85 | if [[ x"${CC}" = x"" ]]; then 86 | CC=gcc 87 | fi 88 | 89 | if [[ x"${CXX}" = x"" ]]; then 90 | CXX=g++ 91 | fi 92 | 93 | c_compiler=`which ${CC}` 94 | cxx_compiler=`which ${CXX}` 95 | cmake=`which cmake` 96 | 97 | if [[ ! -x ${c_compiler} ]]; then 98 | die "cannot found c compiler" 99 | fi 100 | 101 | if [[ ! -x ${cxx_compiler} ]]; then 102 | die "cannot found cplusplus compiler" 103 | fi 104 | 105 | if [[ ! -x ${cmake} ]]; then 106 | die "cannot found cmake" 107 | fi 108 | 109 | # Configure 110 | ${cmake} -DENABLE_DEBUG=${enable_build} -DCMAKE_INSTALL_PREFIX=${prefix_dirs} \ 111 | -DCMAKE_C_COMPILER=${c_compiler} -DCMAKE_CXX_COMPILER=${cxx_compiler} \ 112 | -DCMAKE_PREFIX_PATH=${dependency_dir} -DENABLE_BOOST=${enable_boost} \ 113 | -DENABLE_COVERAGE=${enable_coverage} -DENABLE_LIBCPP=${enable_clang_lib} ${source_dir} \ 114 | || die "failed to configure the project" 115 | 116 | echo 'bootstrap success. Run "make" to build.' 117 | -------------------------------------------------------------------------------- /gmock/include/gmock/internal/gmock-port.h: -------------------------------------------------------------------------------- 1 | // Copyright 2008, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: vadimb@google.com (Vadim Berman) 31 | // 32 | // Low-level types and utilities for porting Google Mock to various 33 | // platforms. They are subject to change without notice. DO NOT USE 34 | // THEM IN USER CODE. 35 | 36 | #ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_ 37 | #define GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_ 38 | 39 | #include 40 | #include 41 | #include 42 | 43 | // Most of the types needed for porting Google Mock are also required 44 | // for Google Test and are defined in gtest-port.h. 45 | #include "gtest/internal/gtest-linked_ptr.h" 46 | #include "gtest/internal/gtest-port.h" 47 | 48 | // To avoid conditional compilation everywhere, we make it 49 | // gmock-port.h's responsibility to #include the header implementing 50 | // tr1/tuple. gmock-port.h does this via gtest-port.h, which is 51 | // guaranteed to pull in the tuple header. 52 | 53 | // For MS Visual C++, check the compiler version. At least VS 2003 is 54 | // required to compile Google Mock. 55 | #if defined(_MSC_VER) && _MSC_VER < 1310 56 | # error "At least Visual C++ 2003 (7.1) is required to compile Google Mock." 57 | #endif 58 | 59 | // Macro for referencing flags. This is public as we want the user to 60 | // use this syntax to reference Google Mock flags. 61 | #define GMOCK_FLAG(name) FLAGS_gmock_##name 62 | 63 | // Macros for declaring flags. 64 | #define GMOCK_DECLARE_bool_(name) extern GTEST_API_ bool GMOCK_FLAG(name) 65 | #define GMOCK_DECLARE_int32_(name) \ 66 | extern GTEST_API_ ::testing::internal::Int32 GMOCK_FLAG(name) 67 | #define GMOCK_DECLARE_string_(name) \ 68 | extern GTEST_API_ ::std::string GMOCK_FLAG(name) 69 | 70 | // Macros for defining flags. 71 | #define GMOCK_DEFINE_bool_(name, default_val, doc) \ 72 | GTEST_API_ bool GMOCK_FLAG(name) = (default_val) 73 | #define GMOCK_DEFINE_int32_(name, default_val, doc) \ 74 | GTEST_API_ ::testing::internal::Int32 GMOCK_FLAG(name) = (default_val) 75 | #define GMOCK_DEFINE_string_(name, default_val, doc) \ 76 | GTEST_API_ ::std::string GMOCK_FLAG(name) = (default_val) 77 | 78 | #endif // GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_ 79 | -------------------------------------------------------------------------------- /test/function/HashJoin/bootstrap: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | die() { 4 | echo "$@" 1>&2 ; exit 1 5 | } 6 | 7 | arg () { 8 | echo "$1" | sed "s/^${2-[^=]*=}//" | sed "s/:/;/g" 9 | } 10 | 11 | # Detect directory information. 12 | source_dir=`cd "\`dirname \"$0\"\`";pwd` 13 | binary_dir=`pwd` 14 | 15 | # Choose the default install prefix. 16 | default_prefix=${source_dir}/dist 17 | 18 | # Choose the default dependency install prefix 19 | default_dependency=${DEPENDENCY_INSTALL_PREFIX} 20 | 21 | if [ x"${default_dependency}" = x"" ]; then 22 | default_dependency="/opt/dependency" 23 | fi 24 | 25 | # Display bootstrap usage 26 | usage() { 27 | echo ' 28 | Usage: '"$0"' [] 29 | Options: [defaults in brackets after descriptions] 30 | Configuration: 31 | --help print this message 32 | --prefix=PREFIX install files in tree rooted at PREFIX 33 | ['"${default_prefix}"'] 34 | --dependency=DIRs specify the dependencies at DIRs, separated by colon 35 | ['"${default_dependency}"'] 36 | --enable-debug enable debug build 37 | --enable-boost force to enable boost 38 | --enable-coverage enable build with code coverage support 39 | --enable-libc++ using libc++ instead of libstdc++, only valid for clang compiler 40 | 41 | Dependencies: 42 | c/c++ compiler 43 | GNU make 44 | cmake http://www.cmake.org/ 45 | boost 1.53+ http://www.boost.org/ 46 | [boost is not required if c++ compiler is g++ 4.6.0+ or clang++ with stdc++] 47 | 48 | Example: 49 | mkdir build 50 | cd build 51 | ../bootstrap --prefix=/path/to/install --dependency=/path/to/thrift:/path/to/protobuf:/path/to/kerberos/:path/to/others 52 | make 53 | make install 54 | ' 55 | exit 10 56 | } 57 | 58 | # Parse arguments 59 | prefix_dirs="${default_prefix}" 60 | dependency_dir="${default_dependency}" 61 | build_type="Release" 62 | enable_boost="ON" 63 | enable_coverage="OFF" 64 | enable_clang_lib="OFF" 65 | while test $# != 0; do 66 | case "$1" in 67 | --prefix=*) dir=`arg "$1"` 68 | prefix_dirs="$dir";; 69 | --dependency=*) dir=`arg "$1"` 70 | dependency_dir="$dir";; 71 | --enable-debug) enable_build="ON";; 72 | --enable-coverage) enable_coverage="ON";; 73 | --enable-libc++) enable_clang_lib="ON";; 74 | --help) usage ;; 75 | *) die "Unknown option: $1" ;; 76 | esac 77 | shift 78 | done 79 | 80 | if [ ${source_dir} = ${binary_dir} ]; then 81 | die "cannot build the project in the source directory! Out-of-source build is enforced!" 82 | fi 83 | 84 | # Check clang compiler 85 | if [[ x"${CC}" = x"" ]]; then 86 | CC=gcc 87 | fi 88 | 89 | if [[ x"${CXX}" = x"" ]]; then 90 | CXX=g++ 91 | fi 92 | 93 | c_compiler=`which ${CC}` 94 | cxx_compiler=`which ${CXX}` 95 | cmake=`which cmake` 96 | 97 | if [[ ! -x ${c_compiler} ]]; then 98 | die "cannot found c compiler" 99 | fi 100 | 101 | if [[ ! -x ${cxx_compiler} ]]; then 102 | die "cannot found cplusplus compiler" 103 | fi 104 | 105 | if [[ ! -x ${cmake} ]]; then 106 | die "cannot found cmake" 107 | fi 108 | 109 | # Configure 110 | ${cmake} -DENABLE_DEBUG=${enable_build} -DCMAKE_INSTALL_PREFIX=${prefix_dirs} \ 111 | -DCMAKE_C_COMPILER=${c_compiler} -DCMAKE_CXX_COMPILER=${cxx_compiler} \ 112 | -DCMAKE_PREFIX_PATH=${dependency_dir} -DENABLE_BOOST=${enable_boost} \ 113 | -DENABLE_COVERAGE=${enable_coverage} -DENABLE_LIBCPP=${enable_clang_lib} ${source_dir} \ 114 | || die "failed to configure the project" 115 | 116 | echo 'bootstrap success. Run "make" to build.' 117 | -------------------------------------------------------------------------------- /test/function/TapeSort/bootstrap: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | die() { 4 | echo "$@" 1>&2 ; exit 1 5 | } 6 | 7 | arg () { 8 | echo "$1" | sed "s/^${2-[^=]*=}//" | sed "s/:/;/g" 9 | } 10 | 11 | # Detect directory information. 12 | source_dir=`cd "\`dirname \"$0\"\`";pwd` 13 | binary_dir=`pwd` 14 | 15 | # Choose the default install prefix. 16 | default_prefix=${source_dir}/dist 17 | 18 | # Choose the default dependency install prefix 19 | default_dependency=${DEPENDENCY_INSTALL_PREFIX} 20 | 21 | if [ x"${default_dependency}" = x"" ]; then 22 | default_dependency="/opt/dependency" 23 | fi 24 | 25 | # Display bootstrap usage 26 | usage() { 27 | echo ' 28 | Usage: '"$0"' [] 29 | Options: [defaults in brackets after descriptions] 30 | Configuration: 31 | --help print this message 32 | --prefix=PREFIX install files in tree rooted at PREFIX 33 | ['"${default_prefix}"'] 34 | --dependency=DIRs specify the dependencies at DIRs, separated by colon 35 | ['"${default_dependency}"'] 36 | --enable-debug enable debug build 37 | --enable-boost force to enable boost 38 | --enable-coverage enable build with code coverage support 39 | --enable-libc++ using libc++ instead of libstdc++, only valid for clang compiler 40 | 41 | Dependencies: 42 | c/c++ compiler 43 | GNU make 44 | cmake http://www.cmake.org/ 45 | boost 1.53+ http://www.boost.org/ 46 | [boost is not required if c++ compiler is g++ 4.6.0+ or clang++ with stdc++] 47 | 48 | Example: 49 | mkdir build 50 | cd build 51 | ../bootstrap --prefix=/path/to/install --dependency=/path/to/thrift:/path/to/protobuf:/path/to/kerberos/:path/to/others 52 | make 53 | make install 54 | ' 55 | exit 10 56 | } 57 | 58 | # Parse arguments 59 | prefix_dirs="${default_prefix}" 60 | dependency_dir="${default_dependency}" 61 | build_type="Release" 62 | enable_boost="ON" 63 | enable_coverage="OFF" 64 | enable_clang_lib="OFF" 65 | while test $# != 0; do 66 | case "$1" in 67 | --prefix=*) dir=`arg "$1"` 68 | prefix_dirs="$dir";; 69 | --dependency=*) dir=`arg "$1"` 70 | dependency_dir="$dir";; 71 | --enable-debug) enable_build="ON";; 72 | --enable-coverage) enable_coverage="ON";; 73 | --enable-libc++) enable_clang_lib="ON";; 74 | --help) usage ;; 75 | *) die "Unknown option: $1" ;; 76 | esac 77 | shift 78 | done 79 | 80 | if [ ${source_dir} = ${binary_dir} ]; then 81 | die "cannot build the project in the source directory! Out-of-source build is enforced!" 82 | fi 83 | 84 | # Check clang compiler 85 | if [[ x"${CC}" = x"" ]]; then 86 | CC=gcc 87 | fi 88 | 89 | if [[ x"${CXX}" = x"" ]]; then 90 | CXX=g++ 91 | fi 92 | 93 | c_compiler=`which ${CC}` 94 | cxx_compiler=`which ${CXX}` 95 | cmake=`which cmake` 96 | 97 | if [[ ! -x ${c_compiler} ]]; then 98 | die "cannot found c compiler" 99 | fi 100 | 101 | if [[ ! -x ${cxx_compiler} ]]; then 102 | die "cannot found cplusplus compiler" 103 | fi 104 | 105 | if [[ ! -x ${cmake} ]]; then 106 | die "cannot found cmake" 107 | fi 108 | 109 | # Configure 110 | ${cmake} -DENABLE_DEBUG=${enable_build} -DCMAKE_INSTALL_PREFIX=${prefix_dirs} \ 111 | -DCMAKE_C_COMPILER=${c_compiler} -DCMAKE_CXX_COMPILER=${cxx_compiler} \ 112 | -DCMAKE_PREFIX_PATH=${dependency_dir} -DENABLE_BOOST=${enable_boost} \ 113 | -DENABLE_COVERAGE=${enable_coverage} -DENABLE_LIBCPP=${enable_clang_lib} ${source_dir} \ 114 | || die "failed to configure the project" 115 | 116 | echo 'bootstrap success. Run "make" to build.' 117 | -------------------------------------------------------------------------------- /test/function/HashJoin/src/recordPtr.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * DBMS Implementation 3 | * Copyright (C) 2013 George Piskas, George Economides 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | * 19 | * Contact: geopiskas@gmail.com 20 | */ 21 | 22 | #include "recordPtr.h" 23 | 24 | // overloading operators for use with struct recordPtr 25 | 26 | bool operator==(const recordPtr &ptr1, const recordPtr &ptr2) { 27 | if (ptr1.block == ptr2.block && ptr1.record == ptr2.record) { 28 | return true; 29 | } else { 30 | return false; 31 | } 32 | } 33 | 34 | bool operator!=(const recordPtr &ptr1, const recordPtr &ptr2) { 35 | return !(ptr1 == ptr2); 36 | } 37 | 38 | bool operator>(const recordPtr &ptr1, const recordPtr &ptr2) { 39 | if (ptr1.block == ptr2.block) { 40 | if (ptr1.record > ptr2.record) { 41 | return true; 42 | } else { 43 | return false; 44 | } 45 | } else { 46 | if (ptr1.block > ptr2.block) { 47 | return true; 48 | } else { 49 | return false; 50 | } 51 | } 52 | } 53 | 54 | bool operator<(const recordPtr &ptr1, const recordPtr &ptr2) { 55 | if (ptr1.block == ptr2.block) { 56 | if (ptr1.record < ptr2.record) { 57 | return true; 58 | } else { 59 | return false; 60 | } 61 | } else { 62 | if (ptr1.block < ptr2.block) { 63 | return true; 64 | } else { 65 | return false; 66 | } 67 | } 68 | } 69 | 70 | bool operator>=(const recordPtr &ptr1, const recordPtr &ptr2) { 71 | if (ptr1 > ptr2 || ptr1 == ptr2) { 72 | return true; 73 | } else { 74 | return false; 75 | } 76 | } 77 | 78 | bool operator<=(const recordPtr &ptr1, const recordPtr &ptr2) { 79 | if (ptr1 < ptr2 || ptr1 == ptr2) { 80 | return true; 81 | } else { 82 | return false; 83 | } 84 | } 85 | 86 | uint operator-(const recordPtr &ptr1, const recordPtr &ptr2) { 87 | return (ptr1.block * MAX_RECORDS_PER_BLOCK + ptr1.record) - (ptr2.block * MAX_RECORDS_PER_BLOCK + ptr2.record); 88 | } 89 | 90 | recordPtr operator+(const recordPtr &ptr, int offset) { 91 | recordPtr result; 92 | result.block = ptr.block + offset / MAX_RECORDS_PER_BLOCK; 93 | int rest = offset % MAX_RECORDS_PER_BLOCK; 94 | 95 | if (ptr.record + rest >= MAX_RECORDS_PER_BLOCK) { 96 | result.block += 1; 97 | result.record = ptr.record + rest - MAX_RECORDS_PER_BLOCK; 98 | } else { 99 | result.record = ptr.record + rest; 100 | } 101 | return result; 102 | } 103 | 104 | recordPtr operator-(const recordPtr &ptr, int offset) { 105 | recordPtr result; 106 | 107 | result.block = ptr.block - offset / MAX_RECORDS_PER_BLOCK; 108 | int rest = offset % MAX_RECORDS_PER_BLOCK; 109 | if (ptr.record - rest < 0) { 110 | result.block -= 1; 111 | result.record = MAX_RECORDS_PER_BLOCK + ptr.record - rest; 112 | } else { 113 | result.record = ptr.record - rest; 114 | } 115 | return result; 116 | } -------------------------------------------------------------------------------- /test/function/TapeSort/src/recordPtr.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * DBMS Implementation 3 | * Copyright (C) 2013 George Piskas, George Economides 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | * 19 | * Contact: geopiskas@gmail.com 20 | */ 21 | 22 | #include "recordPtr.h" 23 | 24 | // overloading operators for use with struct recordPtr 25 | 26 | bool operator==(const recordPtr &ptr1, const recordPtr &ptr2) { 27 | if (ptr1.block == ptr2.block && ptr1.record == ptr2.record) { 28 | return true; 29 | } else { 30 | return false; 31 | } 32 | } 33 | 34 | bool operator!=(const recordPtr &ptr1, const recordPtr &ptr2) { 35 | return !(ptr1 == ptr2); 36 | } 37 | 38 | bool operator>(const recordPtr &ptr1, const recordPtr &ptr2) { 39 | if (ptr1.block == ptr2.block) { 40 | if (ptr1.record > ptr2.record) { 41 | return true; 42 | } else { 43 | return false; 44 | } 45 | } else { 46 | if (ptr1.block > ptr2.block) { 47 | return true; 48 | } else { 49 | return false; 50 | } 51 | } 52 | } 53 | 54 | bool operator<(const recordPtr &ptr1, const recordPtr &ptr2) { 55 | if (ptr1.block == ptr2.block) { 56 | if (ptr1.record < ptr2.record) { 57 | return true; 58 | } else { 59 | return false; 60 | } 61 | } else { 62 | if (ptr1.block < ptr2.block) { 63 | return true; 64 | } else { 65 | return false; 66 | } 67 | } 68 | } 69 | 70 | bool operator>=(const recordPtr &ptr1, const recordPtr &ptr2) { 71 | if (ptr1 > ptr2 || ptr1 == ptr2) { 72 | return true; 73 | } else { 74 | return false; 75 | } 76 | } 77 | 78 | bool operator<=(const recordPtr &ptr1, const recordPtr &ptr2) { 79 | if (ptr1 < ptr2 || ptr1 == ptr2) { 80 | return true; 81 | } else { 82 | return false; 83 | } 84 | } 85 | 86 | uint operator-(const recordPtr &ptr1, const recordPtr &ptr2) { 87 | return (ptr1.block * MAX_RECORDS_PER_BLOCK + ptr1.record) - (ptr2.block * MAX_RECORDS_PER_BLOCK + ptr2.record); 88 | } 89 | 90 | recordPtr operator+(const recordPtr &ptr, int offset) { 91 | recordPtr result; 92 | result.block = ptr.block + offset / MAX_RECORDS_PER_BLOCK; 93 | int rest = offset % MAX_RECORDS_PER_BLOCK; 94 | 95 | if (ptr.record + rest >= MAX_RECORDS_PER_BLOCK) { 96 | result.block += 1; 97 | result.record = ptr.record + rest - MAX_RECORDS_PER_BLOCK; 98 | } else { 99 | result.record = ptr.record + rest; 100 | } 101 | return result; 102 | } 103 | 104 | recordPtr operator-(const recordPtr &ptr, int offset) { 105 | recordPtr result; 106 | 107 | result.block = ptr.block - offset / MAX_RECORDS_PER_BLOCK; 108 | int rest = offset % MAX_RECORDS_PER_BLOCK; 109 | if (ptr.record - rest < 0) { 110 | result.block -= 1; 111 | result.record = MAX_RECORDS_PER_BLOCK + ptr.record - rest; 112 | } else { 113 | result.record = ptr.record - rest; 114 | } 115 | return result; 116 | } -------------------------------------------------------------------------------- /src/file/OutputStream.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * 2017 - 3 | * open source under Apache License Version 2.0 4 | ********************************************************************/ 5 | /** 6 | * Licensed to the Apache Software Foundation (ASF) under one 7 | * or more contributor license agreements. See the NOTICE file 8 | * distributed with this work for additional information 9 | * regarding copyright ownership. The ASF licenses this file 10 | * to you under the Apache License, Version 2.0 (the 11 | * "License"); you may not use this file except in compliance 12 | * with the License. You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | #include "common/Exception.h" 23 | #include "common/ExceptionInternal.h" 24 | #include "file/OutputStream.h" 25 | 26 | namespace Gopherwood { 27 | namespace Internal { 28 | 29 | OutputStream::OutputStream(int fd, shared_ptr status) : 30 | mLocalSpaceFD(fd), mStatus(status) { 31 | mPos = 0; 32 | mBlockOutputStream = shared_ptr(new BlockOutputStream(mLocalSpaceFD)); 33 | } 34 | 35 | void OutputStream::updateBlockStream() { 36 | mBlockOutputStream->flush(); 37 | 38 | /* Update the BlockInfo of the BlockOutputStream */ 39 | mBlockOutputStream->setBlockInfo(mStatus->getCurBlockInfo()); 40 | 41 | /* Update the position*/ 42 | mPos = mStatus->getPosition(); 43 | } 44 | 45 | void OutputStream::write(const char *buffer, int64_t length, bool isSeek) { 46 | int64_t bytesToWrite = length; 47 | int64_t bytesWritten = 0; 48 | bool needUpdate = true; 49 | 50 | /* write the buffer, switch target block if needed */ 51 | while (bytesToWrite > 0) { 52 | /* update BlockOutputStream, flush previous cached data 53 | * and switch to target block id & offset */ 54 | if (needUpdate) { 55 | updateBlockStream(); 56 | needUpdate = false; 57 | } 58 | 59 | /* write to target block */ 60 | int64_t written; 61 | if (bytesToWrite <= mBlockOutputStream->remaining()) { 62 | if (!isSeek){ 63 | written = mBlockOutputStream->write(buffer + bytesWritten, bytesToWrite); 64 | assert(written == bytesToWrite); 65 | } else { 66 | written = bytesToWrite; 67 | } 68 | } else { 69 | if (!isSeek){ 70 | written = mBlockOutputStream->write(buffer + bytesWritten, mBlockOutputStream->remaining()); 71 | assert(written == mBlockOutputStream->remaining()); 72 | } else { 73 | written = mBlockOutputStream->remaining(); 74 | } 75 | needUpdate = true; 76 | } 77 | 78 | 79 | if (written == -1) { 80 | THROW(GopherwoodException, 81 | "[OutputStream::write] write error!"); 82 | } 83 | 84 | /* update statistics */ 85 | bytesToWrite -= written; 86 | bytesWritten += written; 87 | mPos += written; 88 | mStatus->setPosition(mPos); 89 | } 90 | } 91 | 92 | void OutputStream::flush() { 93 | mBlockOutputStream->flush(); 94 | } 95 | 96 | void OutputStream::close() { 97 | mBlockOutputStream->flush(); 98 | } 99 | 100 | 101 | OutputStream::~OutputStream() { 102 | 103 | } 104 | 105 | 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /test/function/TapeSort/src/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * DBMS Implementation 3 | * Copyright (C) 2013 George Piskas, George Economides 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | * 19 | * Contact: geopiskas@gmail.com 20 | */ 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include "dbtproj.h" 30 | #include "fileOps.h" 31 | 32 | using namespace std; 33 | 34 | void printMenu() { 35 | cout << endl << "Press the key with chosen option: " << endl; 36 | cout << "1) format gophrewood" << endl; 37 | cout << "2) TapeSort" << endl; 38 | cout << "3) Exit" << endl; 39 | cout << "> "; 40 | } 41 | 42 | void formatGW() { 43 | formatGopherwood(); 44 | dbtproj::totalReadTime = 0; 45 | } 46 | 47 | 48 | std::string getTime() { 49 | time_t timep; 50 | time(&timep); 51 | char tmp[64]; 52 | strftime(tmp, sizeof(tmp), "%Y-%m-%d %H:%M:%S", localtime(&timep)); 53 | return tmp; 54 | } 55 | 56 | 57 | void testMergeSort() { 58 | 59 | char infile1[] = "infile1-tapeSort.bin"; 60 | char outfile[] = "output-tapeSort.bin"; 61 | 62 | std::cout << "[time. ]start to create the file, time is = " << getTime() << std::endl; 63 | createFile(infile1, 8000); 64 | std::cout << "[time. ]end to create the file, time is = " << getTime() << std::endl; 65 | 66 | 67 | std::cout << "[time. ]start to print the input file, time is = " << getTime() << std::endl; 68 | // printFile(infile1); 69 | std::cout << "[time. ]end to print the input file, time is = " << getTime() << std::endl; 70 | 71 | uint nmem_blocks = 200; 72 | block_t *buffer = (block_t *) malloc(nmem_blocks * sizeof(block_t)); 73 | uint nsorted_segs = 0, npasses = 0, nios = 0, nres = 0, nunique = 0; 74 | 75 | 76 | std::cout << "[time. ]start to merge sort. time is = " << getTime() << std::endl; 77 | dbtproj* dbtproj1 = new dbtproj(); 78 | dbtproj1->MergeSort(infile1, 1, buffer, nmem_blocks, outfile, &nsorted_segs, &npasses, &nios); 79 | std::cout << "[time. ]end to merge sort. time is = " << getTime() << std::endl; 80 | 81 | free(buffer); 82 | printf("nios = %d, npasses = %d, nsorted_segs = %d\n", nios, npasses, nsorted_segs); 83 | 84 | std::cout << "[time. ] totalReadTime = " << dbtproj::totalReadTime << " ms, " 85 | "=" << dbtproj::totalReadTime / 1000 << " s, " 86 | "= " << dbtproj::totalReadTime / 1000 / 60 << " m" << std::endl; 87 | 88 | } 89 | 90 | 91 | int main(int argc, char **argv) { 92 | char input = 0; 93 | while (input != '3') { 94 | do { 95 | cin.sync(); 96 | cin.clear(); 97 | printMenu(); 98 | cin >> input; 99 | } while (!cin.fail() && input != '1' && input != '2' && input != '3'); 100 | 101 | switch (input) { 102 | case '1': 103 | formatGW(); 104 | break; 105 | 106 | case '2': 107 | testMergeSort(); 108 | break; 109 | 110 | case '3': 111 | return 0; 112 | } 113 | } 114 | return 0; 115 | } 116 | 117 | -------------------------------------------------------------------------------- /gmock/include/gmock/gmock.h: -------------------------------------------------------------------------------- 1 | // Copyright 2007, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: wan@google.com (Zhanyong Wan) 31 | 32 | // Google Mock - a framework for writing C++ mock classes. 33 | // 34 | // This is the main header file a user should include. 35 | 36 | #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_H_ 37 | #define GMOCK_INCLUDE_GMOCK_GMOCK_H_ 38 | 39 | // This file implements the following syntax: 40 | // 41 | // ON_CALL(mock_object.Method(...)) 42 | // .With(...) ? 43 | // .WillByDefault(...); 44 | // 45 | // where With() is optional and WillByDefault() must appear exactly 46 | // once. 47 | // 48 | // EXPECT_CALL(mock_object.Method(...)) 49 | // .With(...) ? 50 | // .Times(...) ? 51 | // .InSequence(...) * 52 | // .WillOnce(...) * 53 | // .WillRepeatedly(...) ? 54 | // .RetiresOnSaturation() ? ; 55 | // 56 | // where all clauses are optional and WillOnce() can be repeated. 57 | 58 | #include "gmock/gmock-actions.h" 59 | #include "gmock/gmock-cardinalities.h" 60 | #include "gmock/gmock-generated-actions.h" 61 | #include "gmock/gmock-generated-function-mockers.h" 62 | #include "gmock/gmock-generated-nice-strict.h" 63 | #include "gmock/gmock-generated-matchers.h" 64 | #include "gmock/gmock-matchers.h" 65 | #include "gmock/gmock-more-actions.h" 66 | #include "gmock/gmock-more-matchers.h" 67 | #include "gmock/internal/gmock-internal-utils.h" 68 | 69 | namespace testing { 70 | 71 | // Declares Google Mock flags that we want a user to use programmatically. 72 | GMOCK_DECLARE_bool_(catch_leaked_mocks); 73 | GMOCK_DECLARE_string_(verbose); 74 | 75 | // Initializes Google Mock. This must be called before running the 76 | // tests. In particular, it parses the command line for the flags 77 | // that Google Mock recognizes. Whenever a Google Mock flag is seen, 78 | // it is removed from argv, and *argc is decremented. 79 | // 80 | // No value is returned. Instead, the Google Mock flag variables are 81 | // updated. 82 | // 83 | // Since Google Test is needed for Google Mock to work, this function 84 | // also initializes Google Test and parses its flags, if that hasn't 85 | // been done. 86 | GTEST_API_ void InitGoogleMock(int* argc, char** argv); 87 | 88 | // This overloaded version can be used in Windows programs compiled in 89 | // UNICODE mode. 90 | GTEST_API_ void InitGoogleMock(int* argc, wchar_t** argv); 91 | 92 | } // namespace testing 93 | 94 | #endif // GMOCK_INCLUDE_GMOCK_GMOCK_H_ 95 | -------------------------------------------------------------------------------- /src/common/Logger.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * 2017 - 3 | * open source under Apache License Version 2.0 4 | ********************************************************************/ 5 | /** 6 | * Licensed to the Apache Software Foundation (ASF) under one 7 | * or more contributor license agreements. See the NOTICE file 8 | * distributed with this work for additional information 9 | * regarding copyright ownership. The ASF licenses this file 10 | * to you under the Apache License, Version 2.0 (the 11 | * "License"); you may not use this file except in compliance 12 | * with the License. You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | #include "platform.h" 23 | 24 | #include "Logger.h" 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | #include "DateTime.h" 36 | #include "Thread.h" 37 | 38 | namespace Gopherwood { 39 | namespace Internal { 40 | 41 | Logger RootLogger; 42 | 43 | static mutex LoggerMutex; 44 | static THREAD_LOCAL once_flag Once; 45 | static THREAD_LOCAL char ProcessId[64]; 46 | 47 | const char * SeverityName[] = { "FATAL", "ERROR", "WARNING", "INFO", "DEBUG1", "DEBUG2", "DEBUG3" }; 48 | 49 | static void InitProcessId() { 50 | std::stringstream ss; 51 | ss.imbue(std::locale::classic()); 52 | ss << "p" << getpid() << ", th" << pthread_self(); 53 | snprintf(ProcessId, sizeof(ProcessId), "%s", ss.str().c_str()); 54 | } 55 | 56 | Logger::Logger() : 57 | fd(STDERR_FILENO), severity(DEFAULT_LOG_LEVEL) { 58 | } 59 | 60 | Logger::~Logger() { 61 | } 62 | 63 | void Logger::setOutputFd(int f) { 64 | fd = f; 65 | } 66 | 67 | void Logger::setLogSeverity(LogSeverity l) { 68 | severity = l; 69 | } 70 | 71 | void Logger::printf(LogSeverity s, const char * fmt, ...) { 72 | va_list ap; 73 | 74 | if (s > severity || fd < 0) { 75 | return; 76 | } 77 | 78 | try { 79 | call_once(Once, InitProcessId); 80 | std::vector buffer; 81 | struct tm tm_time; 82 | struct timeval tval; 83 | memset(&tval, 0, sizeof(tval)); 84 | gettimeofday(&tval, NULL); 85 | localtime_r(&tval.tv_sec, &tm_time); 86 | //determine buffer size 87 | va_start(ap, fmt); 88 | int size = vsnprintf(&buffer[0], buffer.size(), fmt, ap); 89 | va_end(ap); 90 | //100 is enough for prefix 91 | buffer.resize(size + 100); 92 | size = snprintf( 93 | &buffer[0], 94 | buffer.size(), 95 | "%04d-%02d-%02d %02d:%02d:%02d.%06ld, %s, %s ", 96 | tm_time.tm_year + 1900, 97 | 1 + tm_time.tm_mon, 98 | tm_time.tm_mday, 99 | tm_time.tm_hour, 100 | tm_time.tm_min, 101 | tm_time.tm_sec, 102 | static_cast(tval.tv_usec), 103 | ProcessId, 104 | SeverityName[s]); 105 | va_start(ap, fmt); 106 | size += vsnprintf(&buffer[size], buffer.size() - size, fmt, ap); 107 | va_end(ap); 108 | lock_guard < mutex > lock(LoggerMutex); 109 | dprintf(fd, "%s\n", &buffer[0]); 110 | return; 111 | } catch (const std::exception & e) { 112 | dprintf( 113 | fd, 114 | "%s:%d %s %s", 115 | __FILE__, 116 | __LINE__, 117 | "FATAL: get an unexpected exception:", 118 | e.what()); 119 | throw; 120 | } 121 | } 122 | 123 | } 124 | } 125 | 126 | -------------------------------------------------------------------------------- /src/common/Hash.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * 2017 - 3 | * open source under Apache License Version 2.0 4 | ********************************************************************/ 5 | /** 6 | * Licensed to the Apache Software Foundation (ASF) under one 7 | * or more contributor license agreements. See the NOTICE file 8 | * distributed with this work for additional information 9 | * regarding copyright ownership. The ASF licenses this file 10 | * to you under the Apache License, Version 2.0 (the 11 | * "License"); you may not use this file except in compliance 12 | * with the License. You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | #ifndef _GOPHERWOOD_COMMON_HASH_H_ 23 | #define _GOPHERWOOD_COMMON_HASH_H_ 24 | 25 | #include "platform.h" 26 | 27 | #include 28 | #include 29 | 30 | #ifdef NEED_BOOST 31 | 32 | #include 33 | 34 | namespace Gopherwood { 35 | namespace Internal { 36 | 37 | /** 38 | * A hash function object used to hash a boolean value. 39 | */ 40 | extern boost::hash BoolHasher; 41 | 42 | /** 43 | * A hash function object used to hash an int value. 44 | */ 45 | extern boost::hash Int32Hasher; 46 | 47 | /** 48 | * A hash function object used to hash an 64 bit int value. 49 | */ 50 | extern boost::hash Int64Hasher; 51 | 52 | /** 53 | * A hash function object used to hash a size_t value. 54 | */ 55 | extern boost::hash SizeHasher; 56 | 57 | /** 58 | * A hash function object used to hash a std::string object. 59 | */ 60 | extern boost::hash StringHasher; 61 | 62 | } 63 | } 64 | 65 | #define GOPHERWOOD_HASH_DEFINE(TYPE) \ 66 | namespace boost{ \ 67 | template<> \ 68 | struct hash { \ 69 | std::size_t operator()(const TYPE & key) const { \ 70 | return key.hash_value(); \ 71 | } \ 72 | }; \ 73 | } 74 | 75 | #else 76 | 77 | #include 78 | 79 | namespace Gopherwood { 80 | namespace Internal { 81 | 82 | /** 83 | * A hash function object used to hash a boolean value. 84 | */ 85 | extern std::hash BoolHasher; 86 | 87 | /** 88 | * A hash function object used to hash an int value. 89 | */ 90 | extern std::hash Int32Hasher; 91 | 92 | /** 93 | * A hash function object used to hash an 64 bit int value. 94 | */ 95 | extern std::hash Int64Hasher; 96 | 97 | /** 98 | * A hash function object used to hash a size_t value. 99 | */ 100 | extern std::hash SizeHasher; 101 | 102 | /** 103 | * A hash function object used to hash a std::string object. 104 | */ 105 | extern std::hash StringHasher; 106 | 107 | } 108 | } 109 | 110 | #define GOPHERWOOD_HASH_DEFINE(TYPE) \ 111 | namespace std{ \ 112 | template<> \ 113 | struct hash { \ 114 | std::size_t operator()(const TYPE & key) const { \ 115 | return key.hash_value(); \ 116 | } \ 117 | }; \ 118 | } 119 | 120 | #endif 121 | 122 | namespace Gopherwood { 123 | namespace Internal { 124 | 125 | /** 126 | * A hash function used to hash a vector of size_t values. 127 | * @param vec The vector's reference which items are to be hashed. 128 | * @param size The size of vec. 129 | * @return The hash value. 130 | * @throw nothrow 131 | */ 132 | static inline size_t CombineHasher(const size_t * vec, size_t size) { 133 | size_t value = 0; 134 | 135 | for (size_t i = 0; i < size; ++i) { 136 | value ^= SizeHasher(vec[i]) << 1; 137 | } 138 | 139 | return value; 140 | } 141 | 142 | } 143 | } 144 | 145 | #endif /* _GOPHERWOOD_COMMON_HASH_H_ */ 146 | -------------------------------------------------------------------------------- /test/function/TapeSort/src/recordOps.h: -------------------------------------------------------------------------------- 1 | /* 2 | * DBMS Implementation 3 | * Copyright (C) 2013 George Piskas, George Economides 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | * 19 | * Contact: geopiskas@gmail.com 20 | */ 21 | 22 | #ifndef RECORDOPS_H 23 | #define RECORDOPS_H 24 | 25 | #include 26 | 27 | #include "dbtproj.h" 28 | #include "recordPtr.h" 29 | 30 | // given a buffer and a recordPtr, returns corresponding record 31 | 32 | inline record_t getRecord(block_t *buffer, recordPtr ptr) { 33 | return buffer[ptr.block].entries[ptr.record]; 34 | } 35 | 36 | // given a buffer, a record and a recordPtr, places the record where recordPtr points 37 | 38 | inline void setRecord(block_t *buffer, record_t rec, recordPtr ptr) { 39 | buffer[ptr.block].entries[ptr.record] = rec; 40 | } 41 | 42 | // given a buffer and 2 recordPtrs, swaps the records where ptrs point 43 | 44 | inline void swapRecords(block_t *buffer, recordPtr ptr1, recordPtr ptr2) { 45 | record_t tmp = getRecord(buffer, ptr1); 46 | setRecord(buffer, getRecord(buffer, ptr2), ptr1); 47 | setRecord(buffer, tmp, ptr2); 48 | } 49 | 50 | // given 2 records and field, compares them 51 | // -1 is returned if rec1 has lower field value than rec2 52 | // 0 is returned if rec1 and rec2 have equal field values 53 | // 1 is returned if rec1 has higher field value than rec2 54 | 55 | inline int compareRecords(record_t rec1, record_t rec2, unsigned char field) { 56 | switch (field) { 57 | case 0: 58 | if (rec1.recid < rec2.recid) { 59 | return -1; 60 | } else if (rec1.recid > rec2.recid) { 61 | return 1; 62 | } 63 | return 0; 64 | case 1: 65 | if (strcmp(rec1.cs_quantity, rec2.cs_quantity) < 0) { 66 | return -1; 67 | } else if (strcmp(rec1.cs_quantity, rec2.cs_quantity) > 0) { 68 | return 1; 69 | } 70 | return 0; 71 | case 2: 72 | if (rec1.cs_quantity < rec2.cs_quantity) { 73 | return -1; 74 | } else if (rec1.cs_quantity > rec2.cs_quantity) { 75 | return 1; 76 | } 77 | return 0; 78 | case 3: 79 | if (rec1.cs_quantity < rec2.cs_quantity) { 80 | return -1; 81 | } else if (rec1.cs_quantity > rec2.cs_quantity) { 82 | return 1; 83 | } 84 | return 0; 85 | } 86 | } 87 | 88 | // hash function for integers 89 | 90 | inline uint hashInt(uint num, uint mod, uint seed) { 91 | num += seed; 92 | num = (num + 0x7ed55d16) + (num << 12); 93 | num = (num ^ 0xc761c23c) ^ (num >> 19); 94 | num = (num + 0x165667b1) + (num << 5); 95 | num = (num + 0xd3a2646c) ^ (num << 9); 96 | num = (num + 0xfd7046c5) + (num << 3); 97 | num = (num ^ 0xb55a4f09) ^ (num >> 16); 98 | return num % mod; 99 | } 100 | 101 | // hash function for strings 102 | 103 | inline uint hashString(char *str, uint mod, uint seed) { 104 | unsigned long hash = 5381; 105 | int c; 106 | 107 | while ((c = *str++)) { 108 | hash = ((hash << 5) + hash) + c; 109 | } 110 | 111 | return hashInt(hash, 8701123, seed) % mod; 112 | } 113 | 114 | // given a record and the field of interest, hashes it and returns a value 115 | 116 | 117 | 118 | // frees memory allocated for a hash index 119 | void destroyHashIndex(linkedRecordPtr **hashIndex, uint size); 120 | 121 | #endif 122 | -------------------------------------------------------------------------------- /src/file/File.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * 2017 - 3 | * open source under Apache License Version 2.0 4 | ********************************************************************/ 5 | /** 6 | * Licensed to the Apache Software Foundation (ASF) under one 7 | * or more contributor license agreements. See the NOTICE file 8 | * distributed with this work for additional information 9 | * regarding copyright ownership. The ASF licenses this file 10 | * to you under the Apache License, Version 2.0 (the 11 | * "License"); you may not use this file except in compliance 12 | * with the License. You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | #include "file/File.h" 23 | #include "common/Exception.h" 24 | #include "common/ExceptionInternal.h" 25 | 26 | namespace Gopherwood { 27 | namespace Internal { 28 | 29 | File::File(FileId id, std::string fileName, int flags, int fd, shared_ptr status) : 30 | id(id), name(fileName), mFlags(flags), localFD(fd), mStatus(status) { 31 | if ((flags & GW_WRONLY) || (flags & GW_RDWR)) { 32 | mOutStream = shared_ptr(new OutputStream(localFD, status)); 33 | } else { 34 | mOutStream = NULL; 35 | } 36 | 37 | mInStream = shared_ptr(new InputStream(localFD, status)); 38 | } 39 | 40 | int64_t File::read(char *buffer, int64_t length) { 41 | int64_t bytesToRead = length < remaining() ? length : remaining(); 42 | if (bytesToRead == 0) { 43 | return 0; 44 | } 45 | 46 | mInStream->read(buffer, bytesToRead); 47 | return bytesToRead; 48 | } 49 | 50 | void File::write(const char *buffer, int64_t length) { 51 | mOutStream->write(buffer, length, false); 52 | } 53 | 54 | void File::flush() { 55 | if ((mFlags & OPEN_TYPE_MASK) == GW_RDONLY) { 56 | THROW(GopherwoodInvalidParmException, "[File] Can not flush a read only file."); 57 | } 58 | mOutStream->flush(); 59 | mStatus->flush(); 60 | } 61 | 62 | int64_t File::seek(int64_t pos, int mode) { 63 | int64_t eof = mStatus->getEof(); 64 | int64_t targetPos = -1; 65 | 66 | if (mode == SEEK_SET) { 67 | targetPos = pos; 68 | } else if (mode == SEEK_CUR) { 69 | targetPos = mStatus->getPosition() + pos; 70 | } else if (mode == SEEK_END) { 71 | targetPos = eof + pos; 72 | } 73 | 74 | if (targetPos >= 0 && targetPos <= eof) { 75 | mStatus->setPosition(targetPos); 76 | } 77 | else if (targetPos > eof) { 78 | /* Only file with Write ActiveStatus can seek to the position exceed eof */ 79 | if ((mFlags & GW_WRONLY) || (mFlags & GW_RDWR)){ 80 | mStatus->setPosition(eof); 81 | mOutStream->write(NULL, targetPos - eof, true); 82 | } else{ 83 | THROW(GopherwoodInvalidParmException, 84 | "[File::seek] Read only file seek position %ld exceed EOF %ld", 85 | targetPos, eof); 86 | } 87 | } 88 | else { 89 | THROW(GopherwoodInvalidParmException, 90 | "[File::seek] invalid seek offset %ld", targetPos); 91 | } 92 | 93 | return targetPos; 94 | } 95 | 96 | void File::close(bool isCancel) { 97 | mStatus->close(isCancel); 98 | 99 | if (mOutStream) { 100 | mOutStream->close(); 101 | } 102 | 103 | if (mInStream) { 104 | mInStream->close(); 105 | } 106 | } 107 | 108 | int64_t File::remaining() { 109 | assert(mStatus->getEof() >= mStatus->getPosition()); 110 | return mStatus->getEof() - mStatus->getPosition(); 111 | 112 | } 113 | 114 | FileId File::getFileId() { 115 | return id; 116 | } 117 | 118 | void File::getFileInfo(GWFileInfo *fileInfo) { 119 | mStatus->getStatistics(fileInfo); 120 | } 121 | 122 | File::~File() { 123 | } 124 | 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /gtest/src/gtest-typed-test.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2008 Google Inc. 2 | // All Rights Reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: wan@google.com (Zhanyong Wan) 31 | 32 | #include "gtest/gtest-typed-test.h" 33 | #include "gtest/gtest.h" 34 | 35 | namespace testing { 36 | namespace internal { 37 | 38 | #if GTEST_HAS_TYPED_TEST_P 39 | 40 | // Skips to the first non-space char in str. Returns an empty string if str 41 | // contains only whitespace characters. 42 | static const char* SkipSpaces(const char* str) { 43 | while (IsSpace(*str)) 44 | str++; 45 | return str; 46 | } 47 | 48 | // Verifies that registered_tests match the test names in 49 | // defined_test_names_; returns registered_tests if successful, or 50 | // aborts the program otherwise. 51 | const char* TypedTestCasePState::VerifyRegisteredTestNames( 52 | const char* file, int line, const char* registered_tests) { 53 | typedef ::std::set::const_iterator DefinedTestIter; 54 | registered_ = true; 55 | 56 | // Skip initial whitespace in registered_tests since some 57 | // preprocessors prefix stringizied literals with whitespace. 58 | registered_tests = SkipSpaces(registered_tests); 59 | 60 | Message errors; 61 | ::std::set tests; 62 | for (const char* names = registered_tests; names != NULL; 63 | names = SkipComma(names)) { 64 | const std::string name = GetPrefixUntilComma(names); 65 | if (tests.count(name) != 0) { 66 | errors << "Test " << name << " is listed more than once.\n"; 67 | continue; 68 | } 69 | 70 | bool found = false; 71 | for (DefinedTestIter it = defined_test_names_.begin(); 72 | it != defined_test_names_.end(); 73 | ++it) { 74 | if (name == *it) { 75 | found = true; 76 | break; 77 | } 78 | } 79 | 80 | if (found) { 81 | tests.insert(name); 82 | } else { 83 | errors << "No test named " << name 84 | << " can be found in this test case.\n"; 85 | } 86 | } 87 | 88 | for (DefinedTestIter it = defined_test_names_.begin(); 89 | it != defined_test_names_.end(); 90 | ++it) { 91 | if (tests.count(*it) == 0) { 92 | errors << "You forgot to list test " << *it << ".\n"; 93 | } 94 | } 95 | 96 | const std::string& errors_str = errors.GetString(); 97 | if (errors_str != "") { 98 | fprintf(stderr, "%s %s", FormatFileLocation(file, line).c_str(), 99 | errors_str.c_str()); 100 | fflush(stderr); 101 | posix::Abort(); 102 | } 103 | 104 | return registered_tests; 105 | } 106 | 107 | #endif // GTEST_HAS_TYPED_TEST_P 108 | 109 | } // namespace internal 110 | } // namespace testing 111 | -------------------------------------------------------------------------------- /src/core/ActiveStatusContext.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * 2017 - 3 | * open source under Apache License Version 2.0 4 | ********************************************************************/ 5 | /** 6 | * Licensed to the Apache Software Foundation (ASF) under one 7 | * or more contributor license agreements. See the NOTICE file 8 | * distributed with this work for additional information 9 | * regarding copyright ownership. The ASF licenses this file 10 | * to you under the Apache License, Version 2.0 (the 11 | * "License"); you may not use this file except in compliance 12 | * with the License. You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | #include "common/Configuration.h" 23 | #include "common/Exception.h" 24 | #include "common/ExceptionInternal.h" 25 | #include "core/ActiveStatusContext.h" 26 | 27 | namespace Gopherwood { 28 | namespace Internal { 29 | 30 | ActiveStatusContext::ActiveStatusContext(shared_ptr sharedMemoryContext) : 31 | mSharedMemoryContext(sharedMemoryContext) { 32 | mThreadPool = shared_ptr(new ThreadPool(Configuration::MAX_LOADER_THREADS)); 33 | } 34 | 35 | shared_ptr ActiveStatusContext::createFileActiveStatus(FileId fileId, 36 | bool isWrite, 37 | bool isSequence, 38 | int localSpaceFD) { 39 | ActiveStatusType type = isWrite ? ActiveStatusType::writeFile : ActiveStatusType::readFile; 40 | 41 | shared_ptr activeStatus = 42 | shared_ptr(new FileActiveStatus(fileId, 43 | mSharedMemoryContext, 44 | mThreadPool, 45 | true, /* isCreate*/ 46 | isSequence, /* isSequence */ 47 | type, 48 | localSpaceFD)); 49 | return activeStatus; 50 | } 51 | 52 | shared_ptr ActiveStatusContext::openFileActiveStatus(FileId fileId, bool isWrite, bool isSequence, int localSpaceFD) { 53 | ActiveStatusType type = isWrite ? ActiveStatusType::writeFile : ActiveStatusType::readFile; 54 | 55 | shared_ptr activeStatus = 56 | shared_ptr(new FileActiveStatus(fileId, 57 | mSharedMemoryContext, 58 | mThreadPool, 59 | false, /* isCreate*/ 60 | isSequence, /* isSequence */ 61 | type, 62 | localSpaceFD)); 63 | return activeStatus; 64 | } 65 | 66 | shared_ptr ActiveStatusContext::deleteFileActiveStatus(FileId fileId, int localSpaceFD) { 67 | shared_ptr activeStatus = 68 | shared_ptr(new FileActiveStatus(fileId, 69 | mSharedMemoryContext, 70 | mThreadPool, 71 | false, /* isCreate*/ 72 | false, /* isSequence */ 73 | ActiveStatusType::deleteFile, 74 | localSpaceFD)); 75 | return activeStatus; 76 | } 77 | 78 | ActiveStatusContext::~ActiveStatusContext() { 79 | } 80 | 81 | } 82 | } -------------------------------------------------------------------------------- /test/function/TapeSort/src/bufferOps.h: -------------------------------------------------------------------------------- 1 | /* 2 | * DBMS Implementation 3 | * Copyright (C) 2013 George Piskas, George Economides 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | * 19 | * Contact: geopiskas@gmail.com 20 | */ 21 | 22 | #ifndef BUFFEROPS_H 23 | #define BUFFEROPS_H 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include "dbtproj.h" 32 | #include "gopherwood.h" 33 | 34 | // empties a block 35 | inline void emptyBlock(block_t *buffer) { 36 | for (int i = 0; i < MAX_RECORDS_PER_BLOCK; i++) { 37 | (*buffer).entries[i].valid = false; 38 | } 39 | (*buffer).nreserved = 0; 40 | } 41 | 42 | // empties the whole buffer 43 | inline void emptyBuffer(block_t *buffer, uint size) { 44 | for (uint i = 0; i < size; i++) { 45 | emptyBlock(buffer + i); 46 | buffer[i].valid = true; 47 | } 48 | } 49 | 50 | 51 | // writes size blocks starting from pointer buffer to the file described 52 | // by fd file descriptor 53 | inline uint writeBlocks(gopherwoodFS gwFS, gwFile gwfile, block_t *buffer, uint size) { 54 | /*********************this is for hashdata master(wuxin)***********************/ 55 | gwSeek(gwFS, gwfile, 0, SEEK_END); 56 | /*********************this is for hashdata master(wuxin)***********************/ 57 | gwWrite(gwFS, gwfile, buffer, size * sizeof(block_t)); 58 | return size; 59 | } 60 | 61 | 62 | // reads size blocks to buffer 63 | inline uint readBlocks(gopherwoodFS gwFS, gwFile gwfile, block_t *buffer, uint size) { 64 | 65 | 66 | struct timeval tv; 67 | gettimeofday(&tv,NULL); 68 | int64_t startTime = tv.tv_sec*1000+tv.tv_usec/1000; 69 | 70 | int64_t tobeReadLength = size * sizeof(block_t); 71 | int64_t haveReadLength = 0; 72 | int64_t readOffset = 0; 73 | while (tobeReadLength > 0) { 74 | haveReadLength = gwRead(gwFS, gwfile, buffer + readOffset, tobeReadLength); 75 | tobeReadLength -= haveReadLength; 76 | readOffset += haveReadLength; 77 | } 78 | if (readOffset != size * sizeof(block_t)) { 79 | std::cout << "readBlocks. actual read length = " << readOffset << ", target read length = " 80 | << size * sizeof(block_t) 81 | << std::endl; 82 | } 83 | 84 | gettimeofday(&tv,NULL); 85 | int64_t endTime = tv.tv_sec*1000+tv.tv_usec/1000; 86 | dbtproj::totalReadTime += endTime-startTime; 87 | 88 | return size; 89 | } 90 | 91 | 92 | // reads size blocks to buffer from a specific point (offset) of the file 93 | 94 | inline uint preadBlocks(gopherwoodFS gwFS, gwFile gwfile, block_t *buffer, uint offset, uint size) { 95 | 96 | struct timeval tv; 97 | gettimeofday(&tv,NULL); 98 | int64_t startTime = tv.tv_sec*1000+tv.tv_usec/1000; 99 | 100 | gwSeek(gwFS, gwfile, offset * sizeof(block_t), SEEK_SET); 101 | int64_t tobeReadLength = size * sizeof(block_t); 102 | int64_t haveReadLength = 0; 103 | int64_t readOffset = 0; 104 | while (tobeReadLength > 0) { 105 | haveReadLength = gwRead(gwFS, gwfile, buffer + readOffset, tobeReadLength); 106 | tobeReadLength -= haveReadLength; 107 | readOffset += haveReadLength; 108 | } 109 | if (readOffset != size * sizeof(block_t)) { 110 | std::cout << "preadBlocks. actual read length = " << readOffset << ", target read length = " 111 | << size * sizeof(block_t) 112 | << std::endl; 113 | } 114 | 115 | gettimeofday(&tv,NULL); 116 | int64_t endTime = tv.tv_sec*1000+tv.tv_usec/1000; 117 | dbtproj::totalReadTime += endTime-startTime; 118 | 119 | return size; 120 | } 121 | 122 | #endif 123 | -------------------------------------------------------------------------------- /test/function/HashJoin/src/dbtproj.h: -------------------------------------------------------------------------------- 1 | /* 2 | * DBMS Implementation 3 | * Copyright (C) 2013 George Piskas, George Economides 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | * 19 | * Contact: geopiskas@gmail.com 20 | */ 21 | 22 | /* 23 | * ========================================================================================== 24 | * Database Technology 2012-2013 25 | * Header file dbtproj.h to be used by your code. 26 | * It is not permitted to change this file. You can make changes to perform tests, 27 | * but please rely on the values and typedefs shown below. 28 | * 29 | * ========================================================================================== 30 | * 31 | */ 32 | 33 | 34 | #ifndef _DBTPROJ_H 35 | #define _DBTPROJ_H 36 | 37 | #include "gopherwood.h" 38 | #include 39 | 40 | #include 41 | 42 | #define STR_LENGTH 32 43 | #define MAX_RECORDS_PER_BLOCK 5000 44 | #define NUM_RANGE 10000000 45 | 46 | #define BLOCK_SIZE 64*1024*1024 47 | #define NUMBER_OF_BLOCKS 27 48 | #define NUM_CONCURRENCY 5 49 | #define SEVERITY 2 50 | 51 | 52 | //#define BLOCK_SIZE 1024*1024 53 | //#define NUMBER_OF_BLOCKS 50 54 | //#define NUM_CONCURRENCY 3 55 | 56 | #define FILE_NAME_1 "/home/ec2-user/datas/catalog_sales.dat" 57 | 58 | #define FILE_NAME_2 "/home/ec2-user/datas/item.dat" 59 | 60 | 61 | /* for function test */ 62 | //#define STR_LENGTH 120 63 | //#define MAX_RECORDS_PER_BLOCK 100 64 | //#define NUM_RANGE 10000 65 | // 66 | //#define BLOCK_SIZE 1*1024*1024 67 | //#define NUMBER_OF_BLOCKS 10 68 | 69 | 70 | 71 | #define WORK_DIR "/media/ephemeral0/goworkspace" 72 | // This is the definition of a record. Contains three fields, recid, num and str 73 | 74 | typedef struct { 75 | int recid; 76 | bool valid; // if set, then this block is valid 77 | char cs_sold_date_sk[STR_LENGTH]; 78 | char cs_sold_time_sk[STR_LENGTH]; 79 | char cs_ship_date_sk[STR_LENGTH]; 80 | char cs_item_sk[STR_LENGTH]; 81 | char cs_quantity[STR_LENGTH]; 82 | } record_t; 83 | 84 | 85 | // This is the definition of a block, which contains a number of fixed-sized records 86 | 87 | typedef struct { 88 | unsigned int blockid; 89 | unsigned int nreserved; // how many reserved entries 90 | record_t entries[MAX_RECORDS_PER_BLOCK]; // array of records 91 | bool valid; // if set, then this block is valid 92 | unsigned char misc; 93 | unsigned int next_blockid; 94 | unsigned int dummy; 95 | } block_t; 96 | 97 | 98 | class dbtproj { 99 | 100 | public: 101 | static gopherwoodFS gwFS; 102 | static int64_t totalReadTime; 103 | 104 | dbtproj() {}; 105 | 106 | ~dbtproj() {}; 107 | 108 | void formatGopherwood(); 109 | 110 | 111 | 112 | 113 | /* ---------------------------------------------------------------------------------------------------------------------- 114 | infile1: the name of the first input file 115 | infile2: the name of the second input file 116 | field: which field will be used for the join: 0 is for recid, 1 is for num, 2 is for str and 3 is for both num and str 117 | buffer: pointer to memory buffer 118 | nmem_blocks: number of blocks in memory 119 | outfile: the name of the output file 120 | nres: number of pairs in output (this should be set by you) 121 | nios: number of IOs performed (this should be set by you) 122 | ---------------------------------------------------------------------------------------------------------------------- 123 | */ 124 | // void 125 | // HashJoin(char *infile1, char *infile2, unsigned char field, block_t *buffer, unsigned int nmem_blocks, 126 | // char *outfile, 127 | // unsigned int *nres, unsigned int *nios); 128 | }; 129 | 130 | 131 | #endif 132 | --------------------------------------------------------------------------------