Skip to content

Commit d401da1

Browse files
committed
DM-52370: Migrated partitioner from boost::shared_ptr to std::shared_ptr
1 parent d55e5df commit d401da1

File tree

13 files changed

+65
-71
lines changed

13 files changed

+65
-71
lines changed

src/partition/ChunkReducer.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
#include <stdexcept>
2828
#include <string>
2929

30-
#include "boost/make_shared.hpp"
31-
3230
#include "partition/ConfigStore.h"
3331

3432
namespace fs = boost::filesystem;
@@ -37,7 +35,7 @@ namespace po = boost::program_options;
3735
namespace lsst::partition {
3836

3937
ChunkReducer::ChunkReducer(ConfigStore const& config)
40-
: _index(boost::make_shared<ChunkIndex>()),
38+
: _index(std::make_shared<ChunkIndex>()),
4139
_chunkId(-1),
4240
_numNodes(config.get<uint32_t>("out.num-nodes")),
4341
_prefix(config.get<std::string>("part.prefix").c_str()), // defend against GCC PR21334

src/partition/ChunkReducer.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
#ifndef LSST_PARTITION_CHUNKREDUCER_H
2424
#define LSST_PARTITION_CHUNKREDUCER_H
2525

26+
#include <memory>
2627
#include <stdint.h>
2728

2829
#include "boost/filesystem/path.hpp"
29-
#include "boost/shared_ptr.hpp"
3030

3131
#include "Chunker.h"
3232
#include "ChunkIndex.h"
@@ -57,12 +57,12 @@ class ChunkReducer : public WorkerBase<ChunkLocation, ChunkIndex> {
5757
void reduce(RecordIter const begin, RecordIter const end);
5858
void finish();
5959

60-
boost::shared_ptr<ChunkIndex> const result() { return _index; }
60+
std::shared_ptr<ChunkIndex> const result() { return _index; }
6161

6262
private:
6363
void _makeFilePaths(int32_t chunkId);
6464

65-
boost::shared_ptr<ChunkIndex> _index;
65+
std::shared_ptr<ChunkIndex> _index;
6666
int32_t _chunkId;
6767
uint32_t _numNodes;
6868
std::string _prefix;

src/partition/InputLines.cc

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include <cstdlib>
2626
#include <stdexcept>
2727

28-
#include "boost/make_shared.hpp"
2928
#include "boost/static_assert.hpp"
3029
#include "boost/thread.hpp"
3130
#include "boost/algorithm/string/predicate.hpp"
@@ -85,11 +84,11 @@ struct LineFragment {
8584

8685
// An input file block.
8786
struct Block {
88-
boost::shared_ptr<InputFile> file;
87+
std::shared_ptr<InputFile> file;
8988
off_t offset;
9089
size_t size;
91-
boost::shared_ptr<LineFragment> head;
92-
boost::shared_ptr<LineFragment> tail;
90+
std::shared_ptr<LineFragment> head;
91+
std::shared_ptr<LineFragment> tail;
9392

9493
Block() : file(), offset(0), size(0), head(), tail() {}
9594

@@ -180,7 +179,7 @@ std::vector<Block> const split(fs::path const &path, off_t blockSize) {
180179

181180
if (boost::algorithm::ends_with(path.c_str(), ".parquet") ||
182181
boost::algorithm::ends_with(path.c_str(), ".parq")) {
183-
b.file = boost::make_shared<InputFileArrow>(path, blockSize);
182+
b.file = std::make_shared<InputFileArrow>(path, blockSize);
184183

185184
b.size = blockSize;
186185
fileSize = b.file->getBatchNumber();
@@ -194,7 +193,7 @@ std::vector<Block> const split(fs::path const &path, off_t blockSize) {
194193
return blocks;
195194
}
196195

197-
b.file = boost::make_shared<InputFile>(path);
196+
b.file = std::make_shared<InputFile>(path);
198197

199198
b.size = blockSize;
200199
fileSize = b.file->size();
@@ -208,7 +207,7 @@ std::vector<Block> const split(fs::path const &path, off_t blockSize) {
208207
b.size = static_cast<size_t>(std::min(fileSize - b.offset, blockSize));
209208
b.head = b.tail;
210209
if (i < numBlocks - 1) {
211-
b.tail = boost::make_shared<LineFragment>();
210+
b.tail = std::make_shared<LineFragment>();
212211
} else {
213212
b.tail.reset();
214213
}
@@ -325,11 +324,11 @@ CharPtrPair const InputLines::Impl::read(char *buf) {
325324
// Method delegation.
326325

327326
InputLines::InputLines(std::vector<fs::path> const &paths, size_t blockSize, bool skipFirstLine)
328-
: _impl(boost::make_shared<Impl>(paths, blockSize, skipFirstLine)) {}
327+
: _impl(std::make_shared<Impl>(paths, blockSize, skipFirstLine)) {}
329328

330329
InputLines::InputLines(std::vector<fs::path> const &paths, size_t blockSize, bool skipFirstLine,
331330
ConfigParamArrow const &configArrow)
332-
: _impl(boost::make_shared<Impl>(paths, blockSize, skipFirstLine, configArrow)) {}
331+
: _impl(std::make_shared<Impl>(paths, blockSize, skipFirstLine, configArrow)) {}
333332

334333
size_t InputLines::getBlockSize() const { return _impl ? _impl->getBlockSize() : 0; }
335334

src/partition/InputLines.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@
2525
/// \file
2626
/// \brief A class for reading lines from a set of text files in parallel.
2727

28+
#include <memory>
2829
#include <sys/types.h>
2930
#include <stdint.h>
3031
#include <utility>
3132
#include <vector>
3233

3334
#include "boost/filesystem.hpp"
34-
#include "boost/shared_ptr.hpp"
3535

3636
// Qserv headers
3737
#include "partition/ParquetInterface.h"
@@ -97,7 +97,7 @@ class InputLines {
9797
private:
9898
class Impl;
9999

100-
boost::shared_ptr<Impl> _impl;
100+
std::shared_ptr<Impl> _impl;
101101
};
102102

103103
} // namespace lsst::partition

src/partition/MapReduce.h

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,19 @@
2626
#ifndef LSST_PARTITION_MAPREDUCE_H
2727
#define LSST_PARTITION_MAPREDUCE_H
2828

29-
#include <sys/types.h>
30-
#include <stdint.h>
29+
#include <algorithm>
3130
#include <cstdlib>
3231
#include <cstring>
33-
#include <algorithm>
32+
#include <memory>
33+
#include <sys/types.h>
3434
#include <stdexcept>
35+
#include <stdint.h>
3536
#include <vector>
3637

3738
#include "boost/filesystem.hpp"
38-
#include "boost/make_shared.hpp"
3939
#include "boost/program_options.hpp"
4040
#include "boost/ref.hpp"
4141
#include "boost/scoped_array.hpp"
42-
#include "boost/shared_ptr.hpp"
4342
#include "boost/thread.hpp"
4443

4544
#include "partition/ConfigStore.h"
@@ -271,7 +270,7 @@ void Silo<K>::_grow() {
271270
/// After all input has been read, mapped and reduced, each worker
272271
/// is asked for a result via:
273272
///
274-
/// boost::shared_ptr<Result> const result();
273+
/// std::shared_ptr<Result> const result();
275274
///
276275
/// The `Result` type must provide the following method:
277276
///
@@ -305,7 +304,7 @@ namespace detail {
305304
/// Comparator for shared pointers to `Silo`s.
306305
template <typename K>
307306
struct SiloPtrCmp {
308-
bool operator()(boost::shared_ptr<Silo<K> > const &s, boost::shared_ptr<Silo<K> > const &t) const {
307+
bool operator()(std::shared_ptr<Silo<K> > const &s, std::shared_ptr<Silo<K> > const &t) const {
309308
return *s < *t;
310309
}
311310
};
@@ -357,7 +356,7 @@ class JobBase {
357356
typedef detail::SortedRecordRange<Key> SortedRecordRange;
358357
typedef typename SortedRecordRange::RecordIter RecordIter;
359358
typedef partition::Silo<Key> Silo;
360-
typedef boost::shared_ptr<Silo> SiloPtr;
359+
typedef std::shared_ptr<Silo> SiloPtr;
361360
typedef detail::SiloPtrCmp<Key> SiloPtrCmp;
362361
typedef typename std::vector<SiloPtr>::const_iterator SiloPtrIter;
363362

@@ -440,7 +439,7 @@ void JobBase<DerivedT, WorkerT>::run(InputLines input) {
440439
std::vector<SiloPtr> silos;
441440
silos.reserve(_numWorkers);
442441
for (uint32_t i = 0; i < _numWorkers; ++i) {
443-
silos.push_back(boost::make_shared<Silo>());
442+
silos.push_back(std::make_shared<Silo>());
444443
}
445444
_silos.swap(silos);
446445
_input = input;
@@ -504,8 +503,8 @@ void JobBase<DerivedT, WorkerT>::defineOptions(boost::program_options::options_d
504503
template <typename DerivedT, typename WorkerT>
505504
void JobBase<DerivedT, WorkerT>::_work() {
506505
// Pre-allocate disk read buffer.
507-
boost::shared_ptr<char> buffer(static_cast<char *>(std::malloc(_input.getMinimumBufferCapacity())),
508-
std::free);
506+
std::shared_ptr<char> buffer(static_cast<char *>(std::malloc(_input.getMinimumBufferCapacity())),
507+
std::free);
509508
if (!buffer) {
510509
throw std::bad_alloc();
511510
}
@@ -652,30 +651,30 @@ class JobImpl : private JobBase<JobImpl<WorkerT, ResultT>, WorkerT> {
652651
typedef JobBase<JobImpl<WorkerT, ResultT>, WorkerT> Base;
653652

654653
void _storeResult(WorkerT &w) {
655-
boost::shared_ptr<ResultT> r = w.result();
654+
std::shared_ptr<ResultT> r = w.result();
656655
if (!_result) {
657656
_result = r;
658657
} else if (r) {
659658
_result->merge(*r);
660659
}
661660
}
662661

663-
boost::shared_ptr<ResultT> _result;
662+
std::shared_ptr<ResultT> _result;
664663

665664
// Allow JobBase to call _storeResult.
666665
friend class JobBase<JobImpl<WorkerT, ResultT>, WorkerT>;
667666

668667
public:
669668
explicit JobImpl(ConfigStore const &config) : Base(config) {}
670669

671-
boost::shared_ptr<ResultT> const run(InputLines input) {
670+
std::shared_ptr<ResultT> const run(InputLines input) {
672671
try {
673672
Base::run(input);
674673
} catch (...) {
675674
_result.reset();
676675
throw;
677676
}
678-
boost::shared_ptr<ResultT> r;
677+
std::shared_ptr<ResultT> r;
679678
r.swap(_result);
680679
return r;
681680
}
@@ -711,7 +710,7 @@ class JobImpl<WorkerT, void> : private JobBase<JobImpl<WorkerT, void>, WorkerT>
711710
///
712711
/// Otherwise, it is:
713712
///
714-
/// boost::shared_ptr<typename WorkerT::Result> const run(InputLines input);
713+
/// std::shared_ptr<typename WorkerT::Result> const run(InputLines input);
715714
///
716715
/// Multiple calls to `run` with different inputs are perfectly legal, and `run`
717716
/// provides the strong exception safety guarantee, at least as far as in-memory

src/partition/sph-duplicate.cc

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@
2828
#include <functional>
2929
#include <iostream>
3030
#include <limits>
31+
#include <memory>
3132
#include <stdexcept>
3233
#include <string>
3334
#include <utility>
3435
#include <vector>
3536

3637
#include "boost/filesystem.hpp"
3738
#include "boost/program_options.hpp"
38-
#include "boost/shared_ptr.hpp"
3939

4040
#include "partition/Chunker.h"
4141
#include "partition/ChunkReducer.h"
@@ -58,7 +58,7 @@ class Duplicator {
5858
public:
5959
Duplicator() : _blockSize(0), _level(-1) {}
6060

61-
boost::shared_ptr<ChunkIndex> const run(ConfigStore const& config);
61+
std::shared_ptr<ChunkIndex> const run(ConfigStore const& config);
6262

6363
private:
6464
// A list of (HTM triangle, chunk ID) pairs.
@@ -70,9 +70,9 @@ class Duplicator {
7070
InputLines const _makeInput() const;
7171

7272
TargetMap _targets;
73-
boost::shared_ptr<Chunker> _chunker;
74-
boost::shared_ptr<HtmIndex> _partIndex;
75-
boost::shared_ptr<HtmIndex> _index;
73+
std::shared_ptr<Chunker> _chunker;
74+
std::shared_ptr<HtmIndex> _partIndex;
75+
std::shared_ptr<HtmIndex> _index;
7676
fs::path _partIndexDir;
7777
fs::path _indexDir;
7878
size_t _blockSize;
@@ -249,8 +249,8 @@ class Worker : public ChunkReducer {
249249
std::vector<ChunkLocation> _locations;
250250
fs::path _partIndexDir;
251251
fs::path _indexDir;
252-
boost::shared_ptr<LessThanCounter> _partIdsLessThan;
253-
boost::shared_ptr<LessThanCounter> _idsLessThan;
252+
std::shared_ptr<LessThanCounter> _partIdsLessThan;
253+
std::shared_ptr<LessThanCounter> _idsLessThan;
254254
};
255255

256256
Worker::Worker(ConfigStore const& config)
@@ -525,13 +525,13 @@ void Worker::defineOptions(po::options_description& opts) {
525525

526526
typedef Job<Worker> DuplicateJob;
527527

528-
boost::shared_ptr<ChunkIndex> const Duplicator::run(ConfigStore const& config) {
528+
std::shared_ptr<ChunkIndex> const Duplicator::run(ConfigStore const& config) {
529529
// Initialize state.
530-
boost::shared_ptr<Chunker> chunker(new Chunker(config));
530+
std::shared_ptr<Chunker> chunker(new Chunker(config));
531531
std::vector<int32_t> chunks = chunksToDuplicate(*chunker, config);
532532
_chunker.swap(chunker);
533533
DuplicateJob job(config);
534-
boost::shared_ptr<ChunkIndex> chunkIndex;
534+
std::shared_ptr<ChunkIndex> chunkIndex;
535535
if (!config.has("id") && !config.has("part.id")) {
536536
throw std::runtime_error(
537537
"One or both of the --id and --part.id "
@@ -575,7 +575,7 @@ boost::shared_ptr<ChunkIndex> const Duplicator::run(ConfigStore const& config) {
575575
chunks.pop_back();
576576
--n;
577577
if (n == 0 || chunks.empty()) {
578-
boost::shared_ptr<ChunkIndex> c = job.run(_makeInput());
578+
std::shared_ptr<ChunkIndex> c = job.run(_makeInput());
579579
if (c) {
580580
if (chunkIndex) {
581581
chunkIndex->merge(*c);
@@ -606,7 +606,7 @@ int main(int argc, char const* const* argv) {
606606
part::ensureOutputFieldExists(config, "part.chunk");
607607
part::ensureOutputFieldExists(config, "part.sub-chunk");
608608
part::makeOutputDirectory(config, true);
609-
boost::shared_ptr<part::ChunkIndex> index = part::duplicator.run(config);
609+
std::shared_ptr<part::ChunkIndex> index = part::duplicator.run(config);
610610
if (!index->empty()) {
611611
fs::path d(config.get<std::string>("out.dir"));
612612
fs::path f = config.get<std::string>("part.prefix") + "_index.bin";

src/partition/sph-estimate-stats.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@
2525
/// counts for the data-sets generated by the duplicator.
2626

2727
#include <iostream>
28+
#include <memory>
2829
#include <stdexcept>
2930
#include <string>
3031
#include <vector>
3132

3233
#include "boost/filesystem.hpp"
3334
#include "boost/program_options.hpp"
34-
#include "boost/shared_ptr.hpp"
3535

3636
#include "partition/Chunker.h"
3737
#include "partition/ChunkIndex.h"
@@ -85,11 +85,11 @@ void defineOptions(po::options_description& opts) {
8585
defineOutputOptions(opts);
8686
}
8787

88-
boost::shared_ptr<ChunkIndex> const estimateStats(std::vector<int32_t> const& chunks, Chunker const& chunker,
89-
HtmIndex const& index, HtmIndex const& partIndex) {
88+
std::shared_ptr<ChunkIndex> const estimateStats(std::vector<int32_t> const& chunks, Chunker const& chunker,
89+
HtmIndex const& index, HtmIndex const& partIndex) {
9090
std::vector<int32_t> subChunks;
9191
std::vector<uint32_t> htmIds;
92-
boost::shared_ptr<ChunkIndex> chunkIndex(new ChunkIndex());
92+
std::shared_ptr<ChunkIndex> chunkIndex(new ChunkIndex());
9393
// loop over chunks
9494
for (std::vector<int32_t>::size_type i = 0; i < chunks.size(); ++i) {
9595
int32_t chunkId = chunks[i];
@@ -126,7 +126,7 @@ boost::shared_ptr<ChunkIndex> const estimateStats(std::vector<int32_t> const& ch
126126
return chunkIndex;
127127
}
128128

129-
boost::shared_ptr<ChunkIndex> const estimateStats(ConfigStore const& config) {
129+
std::shared_ptr<ChunkIndex> const estimateStats(ConfigStore const& config) {
130130
Chunker chunker(config);
131131
if (!config.has("index") && !config.has("part.index")) {
132132
throw std::runtime_error(
@@ -138,8 +138,8 @@ boost::shared_ptr<ChunkIndex> const estimateStats(ConfigStore const& config) {
138138
fs::path indexPath(config.get<std::string>(opt));
139139
opt = (config.has("part.index") ? "part.index" : "index");
140140
fs::path partIndexPath(config.get<std::string>(opt));
141-
boost::shared_ptr<HtmIndex> index(new HtmIndex(indexPath));
142-
boost::shared_ptr<HtmIndex> partIndex;
141+
std::shared_ptr<HtmIndex> index(new HtmIndex(indexPath));
142+
std::shared_ptr<HtmIndex> partIndex;
143143
if (partIndexPath != indexPath) {
144144
partIndex.reset(new HtmIndex(partIndexPath));
145145
} else {
@@ -173,7 +173,7 @@ int main(int argc, char const* const* argv) {
173173
part::defineOptions(options);
174174
part::ConfigStore config = part::parseCommandLine(options, argc, argv, help);
175175
part::makeOutputDirectory(config, true);
176-
boost::shared_ptr<part::ChunkIndex> index = part::estimateStats(config);
176+
std::shared_ptr<part::ChunkIndex> index = part::estimateStats(config);
177177
if (!index->empty()) {
178178
fs::path d(config.get<std::string>("out.dir"));
179179
fs::path f = config.get<std::string>("part.prefix") + "_index.bin";

0 commit comments

Comments
 (0)