Repository: duckdb/duckdb
File: src/storage/wal_replay.cpp (C++)

Code before:
	void ReplayUseTable();
	void ReplayInsert();
	void ReplayRowGroupData();
	void ReplayDelete();
	void ReplayUpdate();
	void ReplayCheckpoint();

private:
	void ReplayIndexData(IndexStorageInfo &info);

private:
	ReplayState &state;
	AttachedDatabase &db;
	ClientContext &context;
	Catalog &catalog;
	unique_ptr<data_t[]> data;
	MemoryStream stream;
	BinaryDeserializer deserializer;
	bool deserialize_only;
	optional_idx expected_checkpoint_id;
};

//===--------------------------------------------------------------------===//
// Replay
//===--------------------------------------------------------------------===//
unique_ptr<WriteAheadLog> WriteAheadLog::Replay(QueryContext &context, FileSystem &fs, AttachedDatabase &db,
                                                const string &wal_path) {
	auto handle = fs.OpenFile(wal_path, FileFlags::FILE_FLAGS_READ | FileFlags::FILE_FLAGS_NULL_IF_NOT_EXISTS);
	if (!handle) {
		// WAL does not exist - instantiate an empty WAL
		return make_uniq<WriteAheadLog>(db, wal_path);
	}

	// context is passed for metric collection purposes only!!
	auto wal_handle = ReplayInternal(context, db, std::move(handle));
	if (wal_handle) {
		return wal_handle;
	}
	// replay returning NULL indicates we can nuke the WAL entirely - but only if this is not a read-only connection
	if (!db.IsReadOnly()) {
		fs.RemoveFile(wal_path);
	}
	return make_uniq<WriteAheadLog>(db, wal_path);
}

// QueryContext is passed for metric collection purposes only!!
unique_ptr<WriteAheadLog> WriteAheadLog::ReplayInternal(QueryContext &context, AttachedDatabase &database,
                                                        unique_ptr<FileHandle> handle) {
	Connection con(database.GetDatabase());
	auto wal_path = handle->GetPath();
	BufferedFileReader reader(FileSystem::Get(database), std::move(handle));

Review comment (suggestion):
Let's not pass `QueryContext` by reference, instead, let's just do `QueryContext context`.

Code after:
	void ReplayInsert();
	void ReplayRowGroupData();
	void ReplayDelete();
	void ReplayUpdate();
	void ReplayCheckpoint();

private:
	void ReplayIndexData(IndexStorageInfo &info);

private:
	ReplayState &state;
	AttachedDatabase &db;
	ClientContext &context;
	Catalog &catalog;
	unique_ptr<data_t[]> data;
	MemoryStream stream;
	BinaryDeserializer deserializer;
	bool deserialize_only;
	optional_idx expected_checkpoint_id;
};

//===--------------------------------------------------------------------===//
// Replay
//===--------------------------------------------------------------------===//
unique_ptr<WriteAheadLog> WriteAheadLog::Replay(QueryContext context, FileSystem &fs, AttachedDatabase &db,
                                                const string &wal_path) {
	auto handle = fs.OpenFile(wal_path, FileFlags::FILE_FLAGS_READ | FileFlags::FILE_FLAGS_NULL_IF_NOT_EXISTS);
	if (!handle) {
		// WAL does not exist - instantiate an empty WAL
		return make_uniq<WriteAheadLog>(db, wal_path);
	}

	// context is passed for metric collection purposes only!!
	auto wal_handle = ReplayInternal(context, db, std::move(handle));
	if (wal_handle) {
		return wal_handle;
	}
	// replay returning NULL indicates we can nuke the WAL entirely - but only if this is not a read-only connection
	if (!db.IsReadOnly()) {
		fs.RemoveFile(wal_path);
	}
	return make_uniq<WriteAheadLog>(db, wal_path);
}

// QueryContext is passed for metric collection purposes only!!
unique_ptr<WriteAheadLog> WriteAheadLog::ReplayInternal(QueryContext context, AttachedDatabase &database,
                                                        unique_ptr<FileHandle> handle) {
	Connection con(database.GetDatabase());
	auto wal_path = handle->GetPath();
	BufferedFileReader reader(FileSystem::Get(database), std::move(handle));
	if (reader.Finished()) {