Skip to content

Commit

Permalink
Merge branch 'main' into v2
Browse files Browse the repository at this point in the history
  • Loading branch information
lalinsky committed Feb 25, 2024
2 parents 3ea1234 + 812d5ba commit c782373
Show file tree
Hide file tree
Showing 27 changed files with 5,310 additions and 4,936 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,36 @@ env:

jobs:
build:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- run: |
sudo apt-get update
sudo apt-get install -y qtbase5-dev libgtest-dev libgrpc++-dev protobuf-compiler-grpc protobuf-compiler libsqlite3-dev
sudo apt-get install -y qt6-base-dev libgtest-dev libgrpc++-dev protobuf-compiler-grpc protobuf-compiler libsqlite3-dev
- run: cmake -DCMAKE_BUILD_TYPE=Release .
- run: make
- run: make check
- run: make package

- name: Log in to the Container registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v1
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v3
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
uses: docker/build-push-action@v2
uses: docker/build-push-action@v5
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -58,7 +58,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1
uses: github/codeql-action/autobuild@v3

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
Expand All @@ -72,4 +72,4 @@ jobs:
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
uses: github/codeql-action/analyze@v3
7 changes: 4 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ set(CMAKE_AUTORCC ON)
find_package(Threads REQUIRED)
find_package(GTest)
find_package(SQLite3 REQUIRED)
find_package(Qt5 COMPONENTS Core Network Concurrent REQUIRED)
find_package(Qt6 COMPONENTS Core Network Concurrent REQUIRED)

find_package(PkgConfig REQUIRED)
pkg_search_module(PROTOBUF REQUIRED IMPORTED_TARGET protobuf)
Expand Down Expand Up @@ -98,10 +98,11 @@ set(fpindexlib_SOURCES
src/store/sqlite/statement.h
src/util/crc.c
src/util/options.cpp
src/util/tracing.cpp
)

add_library(fpindexlib ${fpindexlib_SOURCES})
target_link_libraries(fpindexlib Qt5::Core Qt5::Network Qt5::Concurrent SQLite::SQLite3)
target_link_libraries(fpindexlib Qt6::Core Qt6::Network Qt6::Concurrent SQLite::SQLite3)

set(qhttp_SOURCES
./src/3rdparty/qhttp/src/qhttpserverconnection.cpp
Expand All @@ -116,7 +117,7 @@ set(qhttp_SOURCES
)
add_library(qhttp ${qhttp_SOURCES})
target_include_directories(qhttp PRIVATE ./src/3rdparty/)
target_link_libraries(qhttp Qt5::Core Qt5::Network Qt5::Concurrent)
target_link_libraries(qhttp Qt6::Core Qt6::Network Qt6::Concurrent)

set(fpserver_SOURCES
src/server/listener.cpp
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ubuntu:20.04
FROM ubuntu:22.04

RUN useradd -m -s /bin/bash -u 1000 acoustid

Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,17 @@ Starting server locally:

- C/C++ compiler supporting at least C++17
- CMake
- Qt5, at least the QtCore, QtNetwork and QtConcurrent components
- Qt6, at least the QtCore, QtNetwork and QtConcurrent components
- SQLite3
- GoogleTest (optional)

#### For Ubuntu/Debian

apt install gcc g++ cmake qt6-base-dev libgtest-dev libsqlite3-dev libprotobuf-dev libgrpc++-dev protobuf-compiler protobuf-compiler-grpc

### Building the code

cmake .
cmake --build .

## Usage
Expand Down
23 changes: 13 additions & 10 deletions src/index/index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void setLastOpId(Idx &idx, int64_t id) {
}

Index::Index(DirectorySharedPtr dir, bool create)
: m_lock(QReadWriteLock::Recursive), m_dir(dir), m_deleter(new IndexFileDeleter(dir)) {
: m_lock(), m_dir(dir), m_deleter(new IndexFileDeleter(dir)) {
open(create);
}

Expand Down Expand Up @@ -182,21 +182,24 @@ QSharedPointer<IndexReader> Index::openReader() {
if (!m_open) {
throw IndexIsNotOpen("index is not open");
}
return openReaderPrivate();
locker.unlock();
return QSharedPointer<IndexReader>::create(sharedFromThis());
}

QSharedPointer<IndexWriter> Index::openWriter(bool wait, int64_t timeoutInMSecs) {
QReadLocker locker(&m_lock);
QSharedPointer<IndexReader> Index::openReaderPrivate() {
if (!m_open) {
throw IndexIsNotOpen("index is not open");
}
return openWriterPrivate(wait, QDeadlineTimer(timeoutInMSecs));
return QSharedPointer<IndexReader>::create(sharedFromThis());
}

QSharedPointer<IndexReader> Index::openReaderPrivate() { return QSharedPointer<IndexReader>::create(sharedFromThis()); }

QSharedPointer<IndexWriter> Index::openWriterPrivate(bool wait, QDeadlineTimer deadline) {
acquireWriterLockPrivate(wait, deadline);
QSharedPointer<IndexWriter> Index::openWriter(bool wait, int64_t timeoutInMSecs) {
QReadLocker locker(&m_lock);
if (!m_open) {
throw IndexIsNotOpen("index is not open");
}
acquireWriterLockPrivate(wait, QDeadlineTimer(timeoutInMSecs));
locker.unlock();
return QSharedPointer<IndexWriter>::create(sharedFromThis(), true);
}

Expand Down Expand Up @@ -362,7 +365,7 @@ void Index::flush() {
if (m_threadPool) {
if (!m_writerFuture.isRunning()) {
auto self = sharedFromThis();
m_writerFuture = QtConcurrent::run(m_threadPool, [=]() {
m_writerFuture = QtConcurrent::run(m_threadPool.get(), [=]() {
self->persistUpdates();
});
}
Expand Down
4 changes: 1 addition & 3 deletions src/index/index.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class Index : public BaseIndex, public QEnableSharedFromThis<Index> {
friend class IndexWriter;

QSharedPointer<IndexReader> openReader();
QSharedPointer<IndexReader> openReaderPrivate();
QSharedPointer<IndexWriter> openWriter(bool wait = false, int64_t timeoutInMSecs = -1);

void acquireWriterLock(bool wait = false, int64_t timeoutInMSecs = -1);
Expand All @@ -84,9 +85,6 @@ class Index : public BaseIndex, public QEnableSharedFromThis<Index> {
void releaseInfo(const IndexInfo &info);
void updateInfo(const IndexInfo &oldInfo, const IndexInfo &newInfo, bool updateIndex = false);

QSharedPointer<IndexReader> openReaderPrivate();
QSharedPointer<IndexWriter> openWriterPrivate(bool wait = true,
QDeadlineTimer deadline = QDeadlineTimer(QDeadlineTimer::Forever));
void acquireWriterLockPrivate(bool wait, QDeadlineTimer deadline);

void persistUpdates(const std::shared_ptr<InMemoryIndex> &index);
Expand Down
2 changes: 1 addition & 1 deletion src/index/index_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void IndexWriter::merge(const QList<int>& merge) {

qDebug() << "New segment" << segment.id() << "with checksum" << segment.checksum() << "(merge)";

QSet<int> merged = merge.toSet();
QSet<int> merged(merge.begin(), merge.end());
info.clearSegments();
for (int i = 0; i < segments.size(); i++) {
const SegmentInfo& s = segments.at(i);
Expand Down
2 changes: 2 additions & 0 deletions src/index/search_result.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#ifndef ACOUSTID_INDEX_SEARCH_RESULT_H_
#define ACOUSTID_INDEX_SEARCH_RESULT_H_

#include <iostream>

namespace Acoustid {

class SearchResult {
Expand Down
6 changes: 5 additions & 1 deletion src/index/search_result_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@

using namespace Acoustid;

std::ostream& operator<<(std::ostream& stream, const SearchResult& result) {
namespace Acoustid {

std::ostream& operator<<(std::ostream& stream, const SearchResult & result) {
return stream << "SearchResult(docId=" << result.docId() << ", score=" << result.score() << ", version=" << result.version() <<")";
}

}

TEST(SearchResultTest, SortSearchResults) {
std::vector<SearchResult> results = {
{ 100, 1, 0 },
Expand Down
2 changes: 1 addition & 1 deletion src/index/segment_merge_policy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ QList<int> SegmentMergePolicy::findMerges(const SegmentInfoList& infos)
for (int i = 0; i < infos.size(); i++) {
segments.append(i);
}
qStableSort(segments.begin(), segments.end(), SegmentSizeLessThan(&infos));
std::stable_sort(segments.begin(), segments.end(), SegmentSizeLessThan(&infos));
//qDebug() << "Order after sorting is " << segments;

size_t minSegmentSize = infos.at(segments.last()).blockCount();
Expand Down
2 changes: 2 additions & 0 deletions src/server/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "errors.h"
#include "protocol.h"
#include "metrics.h"
#include "util/tracing.h"

using namespace Acoustid;
using namespace Acoustid::Server;
Expand Down Expand Up @@ -133,6 +134,7 @@ void Connection::readIncomingData()
}

auto futureResult = QtConcurrent::run([=]() {
setTraceId(m_session->getTraceId());
QString response;
try {
response = renderResponse(handler());
Expand Down
Loading

0 comments on commit c782373

Please sign in to comment.