Пример #1
0
	virtual void on_read_finished(const ioremap::elliptics::sync_read_result &result,
			const ioremap::elliptics::error_info &error) {
		if (error.code() == -ENOENT) {
			this->send_reply(swarm::url_fetcher::response::not_found);
			return;
		} else if (error) {
			this->send_reply(swarm::url_fetcher::response::service_unavailable);
			return;
		}

		const ioremap::elliptics::read_result_entry &entry = result[0];

		document doc = storage::unpack_document(entry.file());

		const swarm::http_request &request = this->request();

		if (auto modified_since = request.headers().if_modified_since()) {
			if ((time_t)doc.ts.tsec <= *modified_since) {
				this->send_reply(swarm::url_fetcher::response::not_modified);
				return;
			}
		}

		swarm::url_fetcher::response reply;
		reply.set_code(swarm::url_fetcher::response::ok);
		reply.headers().set_content_length(doc.data.size());
		reply.headers().set_content_type("text/plain");
		reply.headers().set_last_modified(doc.ts.tsec);

		this->send_reply(std::move(reply), std::move(doc.data));
	}
Пример #2
0
void elliptics_service_t::on_bulk_read_completed(deferred<std::map<std::string, std::string> > promise,
	const key_name_map &keys,
	const ioremap::elliptics::sync_read_result &result,
	const ioremap::elliptics::error_info &error)
{
	if (error) {
		promise.abort(-error.code(), error.message());
	} else {
		std::map<std::string, std::string> read_result;

		for (size_t i = 0; i < result.size(); ++i) {
			const auto &entry = result[i];
			const auto &id = reinterpret_cast<const dnet_raw_id &>(entry.command()->id);

			auto it = keys.find(id);

			if (it == keys.end()) {
				continue;
			}

			read_result[it->second] = entry.file().to_string();
		}

		promise.write(read_result);
	}
}
Пример #3
0
void elliptics_service_t::on_remove_completed(deferred<void> promise,
	const ioremap::elliptics::sync_remove_result &,
	const ioremap::elliptics::error_info &error)
{
	if (error) {
		promise.abort(-error.code(), error.message());
	} else {
		promise.close();
	}
}
Пример #4
0
void elliptics_service_t::on_find_completed(deferred<std::vector<std::string> > promise,
	const ioremap::elliptics::sync_find_indexes_result &result,
	const ioremap::elliptics::error_info &error)
{
	if (error) {
		promise.abort(-error.code(), error.message());
	} else {
		promise.write(storage::elliptics_storage_t::convert_list_result(result));
	}
}
Пример #5
0
void elliptics_service_t::on_read_completed(deferred<std::string> promise,
	const ioremap::elliptics::sync_read_result &result,
	const ioremap::elliptics::error_info &error)
{
	if (error) {
		promise.abort(-error.code(), error.message());
	} else {
		promise.write(result[0].file().to_string());
	}
}
Пример #6
0
void proxy::req_delete::on_lookup(const ioremap::elliptics::sync_lookup_result &slr, const ioremap::elliptics::error_info &error) {

	if (error) {
		BH_LOG(logger(), SWARM_LOG_ERROR, "Delete request=\"%s\" lookup error: %s"
				, url_str.c_str(), error.message().c_str());
		HANDY_MDS_DELETE_REPLY(error.code() == -ENOENT ? 404 : 500);
		send_reply(error.code() == -ENOENT ? 404 : 500);
		return;
	}

	const auto &entry = slr.front();
	total_size = entry.file_info()->size;

	// all_with_ack because all doesn't mean all in some cases e.g. remove act
	session->set_filter(ioremap::elliptics::filters::all_with_ack);
	session->set_timeout(server()->timeout.remove);

	BH_LOG(logger(), SWARM_LOG_DEBUG, "Delete %s: data size %d"
			, url_str.c_str(), static_cast<int>(total_size));
	session->remove(key).connect(wrap(std::bind(&req_delete::on_finished, shared_from_this(), std::placeholders::_1, std::placeholders::_2)));
}
Пример #7
0
void proxy::req_get::on_lookup(const ioremap::elliptics::sync_lookup_result &slr, const ioremap::elliptics::error_info &error) {
	if (error) {
		if (error.code() == -ENOENT) {
			BH_LOG(logger(), SWARM_LOG_INFO
					, "Get %s %s: on_lookup: file not found"
					, m_key.remote().c_str(), m_key.to_string().c_str());
			HANDY_MDS_GET_REPLY(404);
			send_reply(404);
		} else {
			BH_LOG(logger(), SWARM_LOG_ERROR
					, "Get %s %s: on_lookup: %s"
					, m_key.remote().c_str(), m_key.to_string().c_str(), error.message().c_str());
			HANDY_MDS_GET_REPLY(500);
			send_reply(500);
		}
		return;
	}
	const auto &entry = slr.front();
	auto total_size = entry.file_info()->size;

	if (m_offset >= total_size) {
		BH_LOG(logger(), SWARM_LOG_INFO
				, "Get %s %s: offset greater than total_size"
				, m_key.remote().c_str()
				, m_key.to_string().c_str());
		HANDY_MDS_GET_REPLY(400);
		send_reply(400);
		return;
	}

	total_size -= m_offset;

	if (m_size == 0 || m_size > total_size) {
		m_size = total_size;
	}

	std::vector<int> groups;
	for (auto it = slr.begin(), end = slr.end(); it != end; ++it) {
		groups.push_back(it->command()->id.group_id);
	}
	m_session->set_groups(groups);

	read_chunk();
}