/* * Copyright (C) 2017 ScyllaDB */ /* * This file is part of Scylla. * * Scylla is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Scylla is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Scylla. If not, see . */ #include "sstable_utils.hh" #include #include "database.hh" #include "memtable-sstable.hh" #include "mutation_reader_assertions.hh" sstables::shared_sstable make_sstable_containing(std::function sst_factory, std::vector muts) { auto sst = sst_factory(); schema_ptr s = muts[0].schema(); auto mt = make_lw_shared(s); std::size_t i{0}; for (auto&& m : muts) { mt->apply(m); ++i; // Give the reactor some time to breathe if(i == 10) { seastar::thread::yield(); i = 0; } } write_memtable_to_sstable(*mt, sst).get(); sst->open_data().get(); std::set merged; for (auto&& m : muts) { auto result = merged.insert(m); if (!result.second) { auto old = *result.first; merged.erase(result.first); merged.insert(old + m); } } // validate the sstable auto rd = assert_that(sst->as_mutation_source()(s)); for (auto&& m : merged) { rd.produces(m); } rd.produces_end_of_stream(); return sst; }