Status EventSubscriberPlugin::add(Row& r, EventTime event_time) { // Get and increment the EID for this module. EventID eid = getEventID(); // Without encouraging a missing event time, do not support a 0-time. r["time"] = std::to_string((event_time == 0) ? getUnixTime() : event_time); // Serialize and store the row data, for query-time retrieval. std::string data; auto status = serializeRowJSON(r, data); if (!status.ok()) { return status; } // Then remove the newline. if (data.size() > 0 && data.back() == '\n') { data.pop_back(); } // Use the last EventID and a checkpoint bucket size to periodically apply // buffer eviction. Eviction occurs if the total count exceeds events_max. if (last_eid_ % EVENTS_CHECKPOINT == 0) { expireCheck(); } // Store the event data. std::string event_key = "data." + dbNamespace() + "." + eid; status = setDatabaseValue(kEvents, event_key, data); // Record the event in the indexing bins, using the index time. recordEvent(eid, event_time); return status; }
Status EventSubscriberPlugin::add(Row& r, EventTime event_time) { std::shared_ptr<DBHandle> db = nullptr; try { db = DBHandle::getInstance(); } catch (const std::runtime_error& e) { return Status(1, e.what()); } // Get and increment the EID for this module. EventID eid = getEventID(); // Without encouraging a missing event time, do not support a 0-time. r["time"] = std::to_string((event_time == 0) ? getUnixTime() : event_time); // Serialize and store the row data, for query-time retrieval. std::string data; auto status = serializeRowJSON(r, data); if (!status.ok()) { return status; } // Use the last EventID and a checkpoint bucket size to periodically apply // buffer eviction. Eviction occurs if the total count exceeds events_max. if (last_eid_ % EVENTS_CHECKPOINT == 0) { expireCheck(); } // Store the event data. std::string event_key = "data." + dbNamespace() + "." + eid; status = db->Put(kEvents, event_key, data); // Record the event in the indexing bins, using the index time. recordEvent(eid, event_time); return status; }