pgsql: convert transaction list to vecdeque

Allows for more efficient removal from front of the list.

Ticket: #5297
pull/7349/head
Jason Ish 4 years ago committed by Victor Julien
parent 2db84726ad
commit 9b0b2beac1

@ -25,6 +25,7 @@ use crate::conf::*;
use crate::core::{AppProto, Flow, ALPROTO_FAILED, ALPROTO_UNKNOWN, IPPROTO_TCP}; use crate::core::{AppProto, Flow, ALPROTO_FAILED, ALPROTO_UNKNOWN, IPPROTO_TCP};
use nom7::{Err, IResult}; use nom7::{Err, IResult};
use std; use std;
use std::collections::VecDeque;
use std::ffi::CString; use std::ffi::CString;
pub const PGSQL_CONFIG_DEFAULT_STREAM_DEPTH: u32 = 0; pub const PGSQL_CONFIG_DEFAULT_STREAM_DEPTH: u32 = 0;
@ -116,7 +117,7 @@ pub enum PgsqlStateProgress {
#[derive(Debug)] #[derive(Debug)]
pub struct PgsqlState { pub struct PgsqlState {
tx_id: u64, tx_id: u64,
transactions: Vec<PgsqlTransaction>, transactions: VecDeque<PgsqlTransaction>,
request_gap: bool, request_gap: bool,
response_gap: bool, response_gap: bool,
backend_secret_key: u32, backend_secret_key: u32,
@ -138,7 +139,7 @@ impl PgsqlState {
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
tx_id: 0, tx_id: 0,
transactions: Vec::new(), transactions: VecDeque::new(),
request_gap: false, request_gap: false,
response_gap: false, response_gap: false,
backend_secret_key: 0, backend_secret_key: 0,
@ -200,11 +201,11 @@ impl PgsqlState {
|| self.state_progress == PgsqlStateProgress::ConnectionTerminated || self.state_progress == PgsqlStateProgress::ConnectionTerminated
{ {
let tx = self.new_tx(); let tx = self.new_tx();
self.transactions.push(tx); self.transactions.push_back(tx);
} }
// If we don't need a new transaction, just return the current one // If we don't need a new transaction, just return the current one
SCLogDebug!("find_or_create state is {:?}", &self.state_progress); SCLogDebug!("find_or_create state is {:?}", &self.state_progress);
return self.transactions.last_mut(); return self.transactions.back_mut();
} }
/// Process State progress to decide if PgsqlTransaction is finished /// Process State progress to decide if PgsqlTransaction is finished
@ -385,7 +386,7 @@ impl PgsqlState {
PgsqlBEMessage::RowDescription(_) => Some(PgsqlStateProgress::RowDescriptionReceived), PgsqlBEMessage::RowDescription(_) => Some(PgsqlStateProgress::RowDescriptionReceived),
PgsqlBEMessage::ConsolidatedDataRow(msg) => { PgsqlBEMessage::ConsolidatedDataRow(msg) => {
// Increment tx.data_size here, since we know msg type, so that we can later on log that info // Increment tx.data_size here, since we know msg type, so that we can later on log that info
self.transactions.last_mut()?.sum_data_size(msg.data_size); self.transactions.back_mut()?.sum_data_size(msg.data_size);
Some(PgsqlStateProgress::DataRowReceived) Some(PgsqlStateProgress::DataRowReceived)
} }
PgsqlBEMessage::CommandComplete(_) => { PgsqlBEMessage::CommandComplete(_) => {

@ -631,9 +631,9 @@ mod tests {
let tx0 = state.new_tx(item0); let tx0 = state.new_tx(item0);
let tx1 = state.new_tx(item1); let tx1 = state.new_tx(item1);
let tx2 = state.new_tx(item2); let tx2 = state.new_tx(item2);
state.transactions.push(tx0); state.transactions.push_back(tx0);
state.transactions.push(tx1); state.transactions.push_back(tx1);
state.transactions.push(tx2); state.transactions.push_back(tx2);
assert_eq!(Some(&state.transactions[1]), state.get_tx(2)); assert_eq!(Some(&state.transactions[1]), state.get_tx(2));
} }

Loading…
Cancel
Save