Skip to content

Commit

Permalink
[C++] Remote Device for FasterKv (#353)
Browse files Browse the repository at this point in the history
* [C++] Add in Azure Blob Store source and test files
* [C++] Integrate Blob device tests with CMakefile
* [C++] Add in an example for FASTER with Blob device
* [C++] Get blob device tests to work against Azurite
* [C++] Update docs with Remote Device description
* [C++] Docs for Remote Device dependencies on Linux
* [C++] Blob device on Windows
* [C++] Blob device compiles on Linux (Not tested)
* [C++] Fix blob device wchar
* [C++] Fix Blob device IO size. If FASTER's page size and the remote tiers max write size don't match, then break down IOs appropriately.
* [C++] Update README for Blob device
* [C++] Comment out Blob device CI
  • Loading branch information
chinkulkarni authored Nov 4, 2020
1 parent e9f5e11 commit 4d9fcde
Show file tree
Hide file tree
Showing 14 changed files with 2,560 additions and 6 deletions.
102 changes: 102 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,105 @@ jobs:
msbuild /t:restore $(solution)
msbuild /p:Configuration=Release $(solution)
displayName: 'Build'
# - job: 'cppBlobsWindows'
# pool:
# vmImage: vs2017-win2016
# displayName: 'C++ Blobs (Windows)'

# strategy:
# maxParallel: 2
# matrix:
# x64-Debug:
# buildPlatform: 'x64'
# buildConfiguration: 'Debug'
# x64-Release:
# buildPlatform: 'x64'
# buildConfiguration: 'Release'

# steps:
# - task: CMake@1
# displayName: 'CMake .. -G"Visual Studio 15 2017 Win64" -DUSE_BLOBS=ON'
# inputs:
# workingDirectory: 'cc/build'
# cmakeArgs: '.. -G"Visual Studio 15 2017 Win64" -DUSE_BLOBS=ON'

# - script: 'git clone https://github.com/microsoft/vcpkg'
# workingDirectory: 'cc/build'
# displayName: 'Download Vcpkg'

# - script: '.\vcpkg\bootstrap-vcpkg.bat'
# workingDirectory: 'cc/build'
# displayName: 'Install Vcpkg'

# - script: '.\vcpkg\vcpkg.exe install azure-storage-cpp:x64-windows'
# workingDirectory: 'cc/build'
# displayName: 'Install Azure dependencies'

# - script: '.\vcpkg\vcpkg.exe integrate install'
# workingDirectory: 'cc/build'
# displayName: 'Integrate vcpkg with msbuild'

# - task: MSBuild@1
# displayName: 'Build solution cc/build/FASTER.sln'
# inputs:
# solution: 'cc/build/FASTER.sln'
# msbuildArguments: '/m /p:Configuration=$(buildConfiguration) /p:Platform=$(buildPlatform)'

# - powershell: 'Invoke-WebRequest -OutFile azure-storage-emulator.msi -Uri "https://go.microsoft.com/fwlink/?LinkId=717179&clcid=0x409"'
# displayName: 'Download Azure Storage Emulator'

# - powershell: 'msiexec /passive /lvx installation.log /a azure-storage-emulator.msi TARGETDIR="C:\storage-emulator"'
# displayName: 'Install Azure Storage Emulator'

# - script: '"C:\Program Files\Microsoft SQL Server\130\Tools\Binn\SqlLocalDB.exe" create "v13.0" 13.0 -s'
# displayName: 'Init Test Db'

# - script: '"C:\storage-emulator\root\Microsoft SDKs\Azure\Storage Emulator\AzureStorageEmulator.exe" start'
# displayName: 'Start Storage Emulator'

# - script: |
# ctest -j 1 --interactive-debug-mode 0 --output-on-failure -C $(buildConfiguration) -R "azure_test"
# ctest -j 1 --interactive-debug-mode 0 --output-on-failure -C $(buildConfiguration) -R "storage_test"
# ctest -j 1 --interactive-debug-mode 0 --output-on-failure -C $(buildConfiguration) -R "faster_blobs_example"
# workingDirectory: 'cc/build'
# displayName: 'Run Ctest'

# - job: 'cppBlobsLinux'
# pool:
# vmImage: ubuntu-18.04
# displayName: 'C++ Blobs (Linux)'

# steps:
# - script: |
# sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
# sudo apt update
# sudo apt install -y libaio-dev uuid-dev libtbb-dev npm
# displayName: 'Install dependencies'

# - script: |
# sudo ./scripts/linux/azure/blob.sh
# workingDirectory: 'cc'
# displayName: 'Install Azure dependencies'

# - script: |
# cd cc
# mkdir -p build/Debug build/Release
# cd build/Debug
# cmake -DCMAKE_BUILD_TYPE=Debug -DUSE_BLOBS=ON ../..
# make -j
# cd ../../build/Release
# cmake -DCMAKE_BUILD_TYPE=Release -DUSE_BLOBS=ON ../..
# make -j
# displayName: 'Compile'

# - script: |
# sudo npm install -g azurite
# azurite -s &
# displayName: 'Install and launch azurite (linux storage emulator)'

# - script: |
# export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
# CTEST_OUTPUT_ON_FAILURE=1 make test
# workingDirectory: 'cc/build/Debug'
# displayName: 'Run Tests (Debug)'
13 changes: 13 additions & 0 deletions cc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ enable_testing()
include(ExternalProject)
project(FASTER)

# The set of additional options that we can pass into cmake. We currently support
# a flag `USE_BLOBS` that will link in azure's blob store library so that FASTER
# can be used with a blob device for the hybrid log.
OPTION(USE_BLOBS "Extend FASTER's hybrid log to blob store" OFF)

if (MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zi /nologo /Gm- /W3 /WX /EHsc /GS /fp:precise /permissive- /Zc:wchar_t /Zc:forScope /Zc:inline /Gd /TP")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /FC /wd4996")
Expand Down Expand Up @@ -72,6 +77,10 @@ if(WIN32)
set(FASTER_TEST_LINK_LIBS ${FASTER_TEST_LINK_LIBS} rpcrt4)
else()
set (FASTER_TEST_LINK_LIBS ${FASTER_TEST_LINK_LIBS} stdc++fs uuid tbb gcc aio m stdc++ pthread)
# Using blob storage. Link in appropriate libraries.
if(USE_BLOBS)
set (FASTER_TEST_LINK_LIBS ${FASTER_TEST_LINK_LIBS} azurestorage cpprest boost_system crypto ssl)
endif()
endif()

# Set the link libraries to for benchmark binary compilation
Expand Down Expand Up @@ -103,3 +112,7 @@ add_subdirectory(playground)
add_subdirectory(src)
add_subdirectory(test)

# Compile tests for blob device too
if(USE_BLOBS)
add_subdirectory(test/blobs)
endif()
51 changes: 51 additions & 0 deletions cc/scripts/linux/azure/blob.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash
#
# Installs all Azure related dependencies to run the blob device.

apt update && \
apt install --assume-yes cmake uuid-dev libboost-all-dev \
libboost-atomic-dev libboost-thread-dev libboost-system-dev \
libboost-date-time-dev libboost-regex-dev libboost-filesystem-dev \
libboost-random-dev libboost-chrono-dev libboost-serialization-dev \
libwebsocketpp-dev openssl libssl-dev ninja-build libxml2-dev g++-5

CASABLANCA_VERSION="v2.10.14"

# Clones, compiles and installs Casablanca (cpprestsdk). The version
# used is that specified in CASABLANCA_VERSION above.
setup_casablanca() {
git clone https://github.com/Microsoft/cpprestsdk.git casablanca
cd casablanca

git checkout tags/"$CASABLANCA_VERSION"
mkdir build.release
cd build.release
cmake -G Ninja .. -DCMAKE_BUILD_TYPE=Release
ninja
ninja install

cd ../
cd ../
}

AZURESTORE_VERSION="v7.0.0"

# Clones, compiles and installs the azure storage cpp library. The version
# used is that specified in AZURESTORE_VERSION above.
setup_azurestore() {
git clone https://github.com/Azure/azure-storage-cpp.git
cd azure-storage-cpp/Microsoft.WindowsAzure.Storage

git checkout tags/"$AZURESTORE_VERSION"
mkdir build.release
cd build.release
CXX=g++-5 cmake .. -DCMAKE_BUILD_TYPE=Release
make -j8
make install

cd ../
cd ../
}

setup_casablanca
setup_azurestore
63 changes: 63 additions & 0 deletions cc/src/common/log.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

#pragma once

#include <time.h>
#include <stdio.h>
#include <stdarg.h>

#include <chrono>

/// Defines the type of log messages supported by the system.
enum class Lvl {
DEBUG = 0,
INFO = 1,
ERR = 2,
};

/// By default, only print ERROR log messages.
#define LEVEL Lvl::INFO

/// Macro to add in the file and function name, and line number.
#ifdef _WIN32
#define logMessage(l, f, ...) logMsg(l, __LINE__, __func__, __FILE__, f, __VA_ARGS__)
#else
#define logMessage(l, f, a...) logMsg(l, __LINE__, __func__, __FILE__, f, ##a)
#endif

/// Prints out a message with the current timestamp and code location.
inline void logMsg(Lvl level, int line, const char* func,
const char* file, const char* fmt, ...)
{
// Do not print messages below the current level.
if (level < static_cast<Lvl>(LEVEL)) return;

auto now = std::chrono::high_resolution_clock::now().time_since_epoch();

va_list argptr;
va_start(argptr, fmt);

char buffer[1024];
vsnprintf(buffer, 1024, fmt, argptr);

std::string l;
switch (level) {
case Lvl::DEBUG:
l = std::string("DEBUG");
break;
case Lvl::INFO:
l = std::string("INFO");
break;
default:
l = std::string("ERROR");
break;
}

fprintf(stderr, "[%010lu.%09lu]::%s::%s:%s:%d:: %s\n",
(unsigned long) std::chrono::duration_cast<std::chrono::seconds>(now).count(),
(unsigned long) std::chrono::duration_cast<std::chrono::nanoseconds>(now).count(),
l.c_str(), file, func, line, buffer);

va_end(argptr);
}
5 changes: 3 additions & 2 deletions cc/src/core/faster.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,10 @@ class FasterKv {
typedef AsyncPendingDeleteContext<key_t> async_pending_delete_context_t;

FasterKv(uint64_t table_size, uint64_t log_size, const std::string& filename,
double log_mutable_fraction = 0.9, bool pre_allocate_log = false)
double log_mutable_fraction = 0.9, bool pre_allocate_log = false,
const std::string& config = "")
: min_table_size_{ table_size }
, disk{ filename, epoch_ }
, disk{ filename, epoch_, config }
, hlog{ filename.empty() /*hasNoBackingStorage*/, log_size, epoch_, disk, disk.log(), log_mutable_fraction, pre_allocate_log }
, system_state_{ Action::None, Phase::REST, 1 }
, num_pending_ios{ 0 } {
Expand Down
Loading

0 comments on commit 4d9fcde

Please sign in to comment.