repo
stringlengths
6
65
file_url
stringlengths
81
311
file_path
stringlengths
6
227
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
7 values
commit_sha
stringlengths
40
40
retrieved_at
stringdate
2026-01-04 15:31:58
2026-01-04 20:25:31
truncated
bool
2 classes
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/http-utils/src/json.rs
libs/http-utils/src/json.rs
use anyhow::Context; use bytes::Buf; use hyper::{Body, Request, Response, StatusCode, header}; use serde::{Deserialize, Serialize}; use super::error::ApiError; /// Parse a json request body and deserialize it to the type `T`. pub async fn json_request<T: for<'de> Deserialize<'de>>( request: &mut Request<Body>, ) ...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/http-utils/src/error.rs
libs/http-utils/src/error.rs
use std::borrow::Cow; use std::error::Error as StdError; use hyper::{Body, Response, StatusCode, header}; use serde::{Deserialize, Serialize}; use thiserror::Error; use tracing::{error, info, warn}; use utils::auth::AuthError; #[derive(Debug, Error)] pub enum ApiError { #[error("Bad request: {0:#?}")] BadRequ...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/http-utils/src/tls_certs.rs
libs/http-utils/src/tls_certs.rs
use std::{sync::Arc, time::Duration}; use anyhow::Context; use arc_swap::ArcSwap; use camino::Utf8Path; use metrics::{IntCounterVec, UIntGaugeVec, register_int_counter_vec, register_uint_gauge_vec}; use once_cell::sync::Lazy; use rustls::{ pki_types::{CertificateDer, PrivateKeyDer, UnixTime}, server::{ClientHe...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/http-utils/src/server.rs
libs/http-utils/src/server.rs
use std::{error::Error, sync::Arc}; use futures::StreamExt; use futures::stream::FuturesUnordered; use hyper0::Body; use hyper0::server::conn::Http; use metrics::{IntCounterVec, register_int_counter_vec}; use once_cell::sync::Lazy; use routerify::{RequestService, RequestServiceBuilder}; use tokio::io::{AsyncRead, Asyn...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/http-utils/src/request.rs
libs/http-utils/src/request.rs
use core::fmt; use std::borrow::Cow; use std::str::FromStr; use anyhow::anyhow; use hyper::body::HttpBody; use hyper::{Body, Request}; use routerify::ext::RequestExt; use super::error::ApiError; pub fn get_request_param<'a>( request: &'a Request<Body>, param_name: &str, ) -> Result<&'a str, ApiError> { m...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/http-utils/src/endpoint.rs
libs/http-utils/src/endpoint.rs
use std::future::Future; use std::io::Write as _; use std::str::FromStr; use std::time::Duration; use anyhow::{Context, anyhow}; use bytes::{Bytes, BytesMut}; use hyper::header::{AUTHORIZATION, CONTENT_DISPOSITION, CONTENT_TYPE, HeaderName}; use hyper::http::HeaderValue; use hyper::{Body, Method, Request, Response}; u...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/desim/src/lib.rs
libs/desim/src/lib.rs
pub mod chan; pub mod executor; pub mod network; pub mod node_os; pub mod options; pub mod proto; pub mod time; pub mod world;
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/desim/src/world.rs
libs/desim/src/world.rs
use std::ops::DerefMut; use std::sync::{Arc, mpsc}; use parking_lot::Mutex; use rand::SeedableRng; use rand::rngs::StdRng; use super::chan::Chan; use super::network::TCP; use super::node_os::NodeOs; use crate::executor::{ExternalHandle, Runtime}; use crate::network::NetworkTask; use crate::options::NetworkOptions; us...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/desim/src/chan.rs
libs/desim/src/chan.rs
use std::collections::VecDeque; use std::sync::Arc; use parking_lot::{Mutex, MutexGuard}; use crate::executor::{self, PollSome, Waker}; /// FIFO channel with blocking send and receive. Can be cloned and shared between threads. /// Blocking functions should be used only from threads that are managed by the executor. ...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/desim/src/network.rs
libs/desim/src/network.rs
use std::cmp::Ordering; use std::collections::{BinaryHeap, VecDeque}; use std::fmt::{self, Debug}; use std::ops::DerefMut; use std::sync::{Arc, mpsc}; use parking_lot::lock_api::{MappedMutexGuard, MutexGuard}; use parking_lot::{Mutex, RawMutex}; use rand::rngs::StdRng; use tracing::debug; use super::chan::Chan; use s...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/desim/src/time.rs
libs/desim/src/time.rs
use std::cmp::Ordering; use std::collections::BinaryHeap; use std::ops::DerefMut; use std::sync::Arc; use std::sync::atomic::{AtomicU32, AtomicU64}; use parking_lot::Mutex; use tracing::trace; use crate::executor::ThreadContext; /// Holds current time and all pending wakeup events. pub struct Timing { /// Curren...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/desim/src/executor.rs
libs/desim/src/executor.rs
use std::panic::AssertUnwindSafe; use std::sync::atomic::{AtomicBool, AtomicU8, AtomicU32, Ordering}; use std::sync::{Arc, OnceLock, mpsc}; use std::thread::JoinHandle; use tracing::{debug, error, trace}; use crate::time::Timing; /// Stores status of the running threads. Threads are registered in the runtime upon cr...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/desim/src/options.rs
libs/desim/src/options.rs
use rand::Rng; use rand::rngs::StdRng; /// Describes random delays and failures. Delay will be uniformly distributed in [min, max]. /// Connection failure will occur with the probablity fail_prob. #[derive(Clone, Debug)] pub struct Delay { pub min: u64, pub max: u64, pub fail_prob: f64, // [0; 1] } impl D...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/desim/src/node_os.rs
libs/desim/src/node_os.rs
use std::sync::Arc; use rand::Rng; use super::chan::Chan; use super::network::TCP; use super::world::{Node, NodeId, World}; use crate::proto::NodeEvent; /// Abstraction with all functions (aka syscalls) available to the node. #[derive(Clone)] pub struct NodeOs { world: Arc<World>, internal: Arc<Node>, } imp...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/desim/src/proto.rs
libs/desim/src/proto.rs
use std::fmt::Debug; use bytes::Bytes; use utils::lsn::Lsn; use crate::network::TCP; use crate::world::NodeId; /// Internal node events. #[derive(Debug)] pub enum NodeEvent { Accept(TCP), Internal(AnyMessage), } /// Events that are coming from a network socket. #[derive(Clone, Debug)] pub enum NetEvent { ...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/desim/tests/reliable_copy_test.rs
libs/desim/tests/reliable_copy_test.rs
//! Simple test to verify that simulator is working. #[cfg(test)] mod reliable_copy_test { use std::sync::Arc; use anyhow::Result; use desim::executor::{self, PollSome}; use desim::node_os::NodeOs; use desim::options::{Delay, NetworkOptions}; use desim::proto::{AnyMessage, NetEvent, NodeEvent, ...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/metrics/src/wrappers.rs
libs/metrics/src/wrappers.rs
use std::io::{Read, Result, Write}; /// A wrapper for an object implementing [Read] /// which allows a closure to observe the amount of bytes read. /// This is useful in conjunction with metrics (e.g. [IntCounter](crate::IntCounter)). /// /// Example: /// /// ``` /// # use std::io::{Result, Read}; /// # use metrics::{...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/metrics/src/lib.rs
libs/metrics/src/lib.rs
//! We re-export those from prometheus crate to //! make sure that we use the same dep version everywhere. //! Otherwise, we might not see all metrics registered via //! a default registry. #![deny(clippy::undocumented_unsafe_blocks)] use std::sync::RwLock; use measured::label::{LabelGroupSet, LabelGroupVisitor, Labe...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/metrics/src/more_process_metrics.rs
libs/metrics/src/more_process_metrics.rs
//! process metrics that the [`::prometheus`] crate doesn't provide. // This module has heavy inspiration from the prometheus crate's `process_collector.rs`. use once_cell::sync::Lazy; use prometheus::Gauge; use crate::UIntGauge; pub struct Collector { descs: Vec<prometheus::core::Desc>, vmlck: crate::UIntG...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/metrics/src/hll.rs
libs/metrics/src/hll.rs
//! HyperLogLog is an algorithm for the count-distinct problem, //! approximating the number of distinct elements in a multiset. //! Calculating the exact cardinality of the distinct elements //! of a multiset requires an amount of memory proportional to //! the cardinality, which is impractical for very large data set...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/metrics/src/launch_timestamp.rs
libs/metrics/src/launch_timestamp.rs
//! A timestamp captured at process startup to identify restarts of the process, e.g., in logs and metrics. use std::fmt::Display; use chrono::Utc; use super::register_uint_gauge; pub struct LaunchTimestamp(chrono::DateTime<Utc>); impl LaunchTimestamp { pub fn generate() -> Self { LaunchTimestamp(Utc::...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/postgres_initdb/src/lib.rs
libs/postgres_initdb/src/lib.rs
//! The canonical way we run `initdb` in Neon. //! //! initdb has implicit defaults that are dependent on the environment, e.g., locales & collations. //! //! This module's job is to eliminate the environment-dependence as much as possible. use std::fmt; use camino::Utf8Path; use postgres_versioninfo::PgMajorVersion;...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/postgres_ffi/build.rs
libs/postgres_ffi/build.rs
extern crate bindgen; use std::env; use std::path::PathBuf; use std::process::Command; use anyhow::{Context, anyhow}; use bindgen::callbacks::{DeriveInfo, ParseCallbacks}; #[derive(Debug)] struct PostgresFfiCallbacks; impl ParseCallbacks for PostgresFfiCallbacks { fn include_file(&self, filename: &str) { ...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/postgres_ffi/wal_craft/src/lib.rs
libs/postgres_ffi/wal_craft/src/lib.rs
use std::ffi::OsStr; use std::path::{Path, PathBuf}; use std::process::Command; use std::time::{Duration, Instant}; use anyhow::{bail, ensure}; use camino_tempfile::{Utf8TempDir, tempdir}; use log::*; use postgres::Client; use postgres::types::PgLsn; use postgres_ffi::{ PgMajorVersion, WAL_SEGMENT_SIZE, XLOG_BLCKS...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/postgres_ffi/wal_craft/src/xlog_utils_test.rs
libs/postgres_ffi/wal_craft/src/xlog_utils_test.rs
//! Tests for postgres_ffi xlog_utils module. Put it here to break cyclic dependency. use super::*; use crate::{error, info}; use regex::Regex; use std::cmp::min; use std::ffi::OsStr; use std::fs::{self, File}; use std::io::Write; use std::{env, str::FromStr}; use utils::const_assert; use utils::lsn::Lsn; fn init_log...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/postgres_ffi/wal_craft/src/bin/wal_craft.rs
libs/postgres_ffi/wal_craft/src/bin/wal_craft.rs
use std::path::PathBuf; use std::str::FromStr; use anyhow::*; use clap::{Arg, ArgMatches, Command, value_parser}; use postgres::Client; use postgres_ffi::PgMajorVersion; use wal_craft::*; fn main() -> Result<()> { env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("wal_craft=info")) ...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/postgres_ffi/src/wal_craft_test_export.rs
libs/postgres_ffi/src/wal_craft_test_export.rs
//! This module is for WAL craft to test with postgres_ffi. Should not import any thing in normal usage. pub use super::PG_MAJORVERSION; pub use super::xlog_utils::*; pub use super::bindings::*; pub use crate::WAL_SEGMENT_SIZE;
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/postgres_ffi/src/pg_constants_v14.rs
libs/postgres_ffi/src/pg_constants_v14.rs
use crate::PgMajorVersion; pub const MY_PGVERSION: PgMajorVersion = PgMajorVersion::PG14; pub const XLOG_DBASE_CREATE: u8 = 0x00; pub const XLOG_DBASE_DROP: u8 = 0x10; pub const BKPIMAGE_IS_COMPRESSED: u8 = 0x02; /* page image is compressed */ pub const BKPIMAGE_APPLY: u8 = 0x04; /* page image should be restored dur...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/postgres_ffi/src/nonrelfile_utils.rs
libs/postgres_ffi/src/nonrelfile_utils.rs
//! //! Common utilities for dealing with PostgreSQL non-relation files. //! use crate::pg_constants; use crate::transaction_id_precedes; use bytes::BytesMut; use super::bindings::MultiXactId; pub fn transaction_id_set_status(xid: u32, status: u8, page: &mut BytesMut) { tracing::trace!( "handle_apply_requ...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/postgres_ffi/src/lib.rs
libs/postgres_ffi/src/lib.rs
#![allow(non_upper_case_globals)] #![allow(non_camel_case_types)] #![allow(non_snake_case)] // bindgen creates some unsafe code with no doc comments. #![allow(clippy::missing_safety_doc)] // noted at 1.63 that in many cases there's u32 -> u32 transmutes in bindgen code. #![allow(clippy::useless_transmute)] // modules i...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/postgres_ffi/src/pg_constants.rs
libs/postgres_ffi/src/pg_constants.rs
//! //! Misc constants, copied from PostgreSQL headers. //! //! Only place version-independent constants here. //! //! TODO: These probably should be auto-generated using bindgen, //! rather than copied by hand. Although on the other hand, it's nice //! to have them all here in one place, and have the ability to add //...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/postgres_ffi/src/pg_constants_v16.rs
libs/postgres_ffi/src/pg_constants_v16.rs
use crate::PgMajorVersion; pub const MY_PGVERSION: PgMajorVersion = PgMajorVersion::PG16; pub const XACT_XINFO_HAS_DROPPED_STATS: u32 = 1u32 << 8; pub const XLOG_DBASE_CREATE_FILE_COPY: u8 = 0x00; pub const XLOG_DBASE_CREATE_WAL_LOG: u8 = 0x10; pub const XLOG_DBASE_DROP: u8 = 0x20; pub const BKPIMAGE_APPLY: u8 = 0x...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/postgres_ffi/src/pg_constants_v15.rs
libs/postgres_ffi/src/pg_constants_v15.rs
use crate::PgMajorVersion; pub const MY_PGVERSION: PgMajorVersion = PgMajorVersion::PG15; pub const XACT_XINFO_HAS_DROPPED_STATS: u32 = 1u32 << 8; pub const XLOG_DBASE_CREATE_FILE_COPY: u8 = 0x00; pub const XLOG_DBASE_CREATE_WAL_LOG: u8 = 0x10; pub const XLOG_DBASE_DROP: u8 = 0x20; pub const BKPIMAGE_APPLY: u8 = 0x...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/postgres_ffi/src/pg_constants_v17.rs
libs/postgres_ffi/src/pg_constants_v17.rs
use crate::PgMajorVersion; pub const MY_PGVERSION: PgMajorVersion = PgMajorVersion::PG17; pub const XACT_XINFO_HAS_DROPPED_STATS: u32 = 1u32 << 8; pub const XLOG_DBASE_CREATE_FILE_COPY: u8 = 0x00; pub const XLOG_DBASE_CREATE_WAL_LOG: u8 = 0x10; pub const XLOG_DBASE_DROP: u8 = 0x20; pub const BKPIMAGE_APPLY: u8 = 0x...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/postgres_ffi/src/xlog_utils.rs
libs/postgres_ffi/src/xlog_utils.rs
// // This file contains common utilities for dealing with PostgreSQL WAL files and // LSNs. // // Many of these functions have been copied from PostgreSQL, and rewritten in // Rust. That's why they don't follow the usual Rust naming conventions, they // have been named the same as the corresponding PostgreSQL function...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/postgres_ffi/src/walrecord.rs
libs/postgres_ffi/src/walrecord.rs
//! This module houses types used in decoding of PG WAL //! records. //! //! TODO: Generate separate types for each supported PG version use bytes::{Buf, Bytes}; use postgres_ffi_types::TimestampTz; use serde::{Deserialize, Serialize}; use utils::bin_ser::DeserializeError; use utils::lsn::Lsn; use crate::{ BLCKSZ...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
true
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/postgres_ffi/src/waldecoder_handler.rs
libs/postgres_ffi/src/waldecoder_handler.rs
//! //! Basic WAL stream decoding. //! //! This understands the WAL page and record format, enough to figure out where the WAL record //! boundaries are, and to reassemble WAL records that cross page boundaries. //! //! This functionality is needed by both the pageserver and the safekeepers. The pageserver needs //! to...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/postgres_ffi/src/wal_generator.rs
libs/postgres_ffi/src/wal_generator.rs
use std::ffi::{CStr, CString}; use bytes::{Bytes, BytesMut}; use crc32c::crc32c_append; use utils::lsn::Lsn; use super::bindings::{RmgrId, XLogLongPageHeaderData, XLogPageHeaderData, XLOG_PAGE_MAGIC}; use super::xlog_utils::{ XlLogicalMessage, XLOG_RECORD_CRC_OFFS, XLOG_SIZE_OF_XLOG_RECORD, XLP_BKP_REMOVABLE, ...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/postgres_ffi/src/controlfile_utils.rs
libs/postgres_ffi/src/controlfile_utils.rs
//! //! Utilities for reading and writing the PostgreSQL control file. //! //! The PostgreSQL control file is one the first things that the PostgreSQL //! server reads when it starts up. It indicates whether the server was shut //! down cleanly, or if it crashed or was restored from online backup so that //! WAL recove...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/postgres_ffi/src/relfile_utils.rs
libs/postgres_ffi/src/relfile_utils.rs
//! //! Common utilities for dealing with PostgreSQL relation files. //! use once_cell::sync::OnceCell; use regex::Regex; use postgres_ffi_types::forknum::*; /// Parse a filename of a relation file. Returns (relfilenode, forknum, segno) tuple. /// /// Formats: /// /// ```text /// <oid> /// <oid>_<fork name> /// <oid>...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/postgres_ffi/benches/waldecoder.rs
libs/postgres_ffi/benches/waldecoder.rs
use std::ffi::CStr; use criterion::{Bencher, Criterion, criterion_group, criterion_main}; use postgres_ffi::v17::wal_generator::LogicalMessageGenerator; use postgres_ffi::v17::waldecoder_handler::WalStreamDecoderHandler; use postgres_ffi::waldecoder::WalStreamDecoder; use postgres_versioninfo::PgMajorVersion; use ppro...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/utils/src/serde_percent.rs
libs/utils/src/serde_percent.rs
//! A serde::Deserialize type for percentages. //! //! See [`Percent`] for details. use serde::{Deserialize, Serialize}; /// If the value is not an integer between 0 and 100, /// deserialization fails with a descriptive error. #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/utils/src/backoff.rs
libs/utils/src/backoff.rs
use std::fmt::{Debug, Display}; use std::time::Duration; use futures::Future; use tokio_util::sync::CancellationToken; pub const DEFAULT_BASE_BACKOFF_SECONDS: f64 = 0.1; pub const DEFAULT_MAX_BACKOFF_SECONDS: f64 = 3.0; pub async fn exponential_backoff( n: u32, base_increment: f64, max_seconds: f64, ...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/utils/src/pid_file.rs
libs/utils/src/pid_file.rs
//! Abstraction to create & read pidfiles. //! //! A pidfile is a file in the filesystem that stores a process's PID. //! Its purpose is to implement a singleton behavior where only //! one process of some "kind" is supposed to be running at a given time. //! The "kind" is identified by the pidfile. //! //! During proc...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/utils/src/measured_stream.rs
libs/utils/src/measured_stream.rs
use std::io::Read; use std::pin::Pin; use std::{io, task}; use pin_project_lite::pin_project; use tokio::io::{AsyncRead, AsyncWrite, ReadBuf}; pin_project! { /// This stream tracks all writes and calls user provided /// callback when the underlying stream is flushed. pub struct MeasuredStream<S, R, W> { ...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/utils/src/rate_limit.rs
libs/utils/src/rate_limit.rs
//! A helper to rate limit operations. use std::time::{Duration, Instant}; pub struct RateLimit { last: Option<Instant>, interval: Duration, dropped: u64, } pub struct RateLimitStats(u64); impl std::fmt::Display for RateLimitStats { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { ...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/utils/src/lib.rs
libs/utils/src/lib.rs
//! `utils` is intended to be a place to put code that is shared //! between other crates in this repository. #![deny(clippy::undocumented_unsafe_blocks)] pub mod backoff; /// `Lsn` type implements common tasks on Log Sequence Numbers pub mod lsn; /// SeqWait allows waiting for a future sequence number to arrive pub ...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/utils/src/failpoint_support.rs
libs/utils/src/failpoint_support.rs
//! Failpoint support code shared between pageserver and safekeepers. use tokio_util::sync::CancellationToken; /// Declare a failpoint that can use to `pause` failpoint action. /// We don't want to block the executor thread, hence, spawn_blocking + await. /// /// Optionally pass a cancellation token, and this failpoi...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/utils/src/sentry_init.rs
libs/utils/src/sentry_init.rs
use std::borrow::Cow; use std::env; use sentry::ClientInitGuard; pub use sentry::release_name; use tracing::{error, info}; #[must_use] pub fn init_sentry( release_name: Option<Cow<'static, str>>, extra_options: &[(&str, &str)], ) -> Option<ClientInitGuard> { let Ok(dsn) = env::var("SENTRY_DSN") else { ...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/utils/src/timeout.rs
libs/utils/src/timeout.rs
use std::time::Duration; use tokio_util::sync::CancellationToken; #[derive(thiserror::Error, Debug)] pub enum TimeoutCancellableError { #[error("Timed out")] Timeout, #[error("Cancelled")] Cancelled, } /// Wrap [`tokio::time::timeout`] with a CancellationToken. /// /// This wrapper is appropriate for...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/utils/src/lock_file.rs
libs/utils/src/lock_file.rs
//! A module to create and read lock files. //! //! File locking is done using [`nix::fcntl::Flock`] exclusive locks. //! The only consumer of this module is currently //! [`pid_file`](crate::pid_file). See the module-level comment //! there for potential pitfalls with lock files that are used //! to store PIDs (pidfil...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/utils/src/id.rs
libs/utils/src/id.rs
use std::fmt; use std::num::ParseIntError; use std::str::FromStr; use anyhow::Context; use hex::FromHex; use rand::Rng; use serde::de::Visitor; use serde::{Deserialize, Serialize}; use thiserror::Error; #[derive(Error, Debug)] pub enum IdError { #[error("invalid id length {0}")] SliceParseError(usize), } ///...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/utils/src/completion.rs
libs/utils/src/completion.rs
use tokio_util::task::TaskTracker; use tokio_util::task::task_tracker::TaskTrackerToken; /// While a reference is kept around, the associated [`Barrier::wait`] will wait. /// /// Can be cloned, moved and kept around in futures as "guard objects". #[derive(Clone)] pub struct Completion { token: TaskTrackerToken, } ...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/utils/src/sync.rs
libs/utils/src/sync.rs
pub mod heavier_once_cell; pub mod duplex; pub mod gate; pub mod spsc_fold;
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/utils/src/poison.rs
libs/utils/src/poison.rs
//! Protect a piece of state from reuse after it is left in an inconsistent state. //! //! # Example //! //! ``` //! # tokio::runtime::Builder::new_current_thread().enable_all().build().unwrap().block_on(async { //! use utils::poison::Poison; //! use std::time::Duration; //! //! struct State { //! clean: bool...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/utils/src/yielding_loop.rs
libs/utils/src/yielding_loop.rs
use tokio_util::sync::CancellationToken; #[derive(thiserror::Error, Debug)] pub enum YieldingLoopError { #[error("Cancelled")] Cancelled, } /// Helper for long synchronous loops, e.g. over all tenants in the system. /// /// Periodically yields to avoid blocking the executor, and after resuming /// checks the ...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/utils/src/generation.rs
libs/utils/src/generation.rs
use std::fmt::Debug; use serde::{Deserialize, Serialize}; /// Tenant generations are used to provide split-brain safety and allow /// multiple pageservers to attach the same tenant concurrently. /// /// See docs/rfcs/025-generation-numbers.md for detail on how generation /// numbers are used. #[derive(Copy, Clone, Eq...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/utils/src/shard.rs
libs/utils/src/shard.rs
//! See `pageserver_api::shard` for description on sharding. use std::ops::RangeInclusive; use std::str::FromStr; use hex::FromHex; use serde::{Deserialize, Serialize}; use crate::id::TenantId; #[derive(Ord, PartialOrd, Eq, PartialEq, Clone, Copy, Serialize, Deserialize, Debug, Hash)] pub struct ShardNumber(pub u8)...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/utils/src/serde_system_time.rs
libs/utils/src/serde_system_time.rs
//! A `serde::{Deserialize,Serialize}` type for SystemTime with RFC3339 format and millisecond precision. #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, serde::Serialize, serde::Deserialize)] #[serde(transparent)] pub struct SystemTime( #[serde( deserialize_with = "deser_rfc3339_millis", se...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/utils/src/simple_rcu.rs
libs/utils/src/simple_rcu.rs
//! //! RCU stands for Read-Copy-Update. It's a synchronization mechanism somewhat //! similar to a lock, but it allows readers to "hold on" to an old value of RCU //! without blocking writers, and allows writing a new value without blocking //! readers. When you update the value, the new value is immediately visible /...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/utils/src/crashsafe.rs
libs/utils/src/crashsafe.rs
use std::borrow::Cow; use std::fs::{self, File}; use std::io::{self, Write}; use std::os::fd::AsFd; use camino::{Utf8Path, Utf8PathBuf}; /// Similar to [`std::fs::create_dir`], except we fsync the /// created directory and its parent. pub fn create_dir(path: impl AsRef<Utf8Path>) -> io::Result<()> { let path = pa...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/utils/src/hex.rs
libs/utils/src/hex.rs
/// Useful type for asserting that expected bytes match reporting the bytes more readable /// array-syntax compatible hex bytes. /// /// # Usage /// /// ``` /// use utils::Hex; /// /// let actual = serialize_something(); /// let expected = [0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64]; /// /// // t...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/utils/src/tcp_listener.rs
libs/utils/src/tcp_listener.rs
use std::io; use std::net::{TcpListener, ToSocketAddrs}; use nix::sys::socket::setsockopt; use nix::sys::socket::sockopt::ReuseAddr; /// Bind a [`TcpListener`] to addr with `SO_REUSEADDR` set to true. pub fn bind<A: ToSocketAddrs>(addr: A) -> io::Result<TcpListener> { let listener = TcpListener::bind(addr)?; ...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/utils/src/env.rs
libs/utils/src/env.rs
//! Wrapper around `std::env::var` for parsing environment variables. use std::fmt::Display; use std::str::FromStr; /// For types `V` that implement [`FromStr`]. pub fn var<V, E>(varname: &str) -> Option<V> where V: FromStr<Err = E>, E: Display, { match std::env::var(varname) { Ok(s) => Some( ...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/utils/src/zstd.rs
libs/utils/src/zstd.rs
use std::io::SeekFrom; use anyhow::{Context, Result}; use async_compression::Level; use async_compression::tokio::bufread::ZstdDecoder; use async_compression::tokio::write::ZstdEncoder; use async_compression::zstd::CParameter; use camino::Utf8Path; use nix::NixPath; use tokio::fs::{File, OpenOptions}; use tokio::io::{...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/utils/src/try_rcu.rs
libs/utils/src/try_rcu.rs
//! Try RCU extension lifted from <https://github.com/vorner/arc-swap/issues/94#issuecomment-1987154023> pub trait ArcSwapExt<T> { /// [`ArcSwap::rcu`](arc_swap::ArcSwap::rcu), but with Result that short-circuits on error. fn try_rcu<R, F, E>(&self, f: F) -> Result<T, E> where F: FnMut(&T) -> Resul...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/utils/src/elapsed_accum.rs
libs/utils/src/elapsed_accum.rs
use std::time::{Duration, Instant}; #[derive(Default)] pub struct ElapsedAccum { accum: Duration, } impl ElapsedAccum { pub fn get(&self) -> Duration { self.accum } pub fn guard(&mut self) -> impl Drop + '_ { let start = Instant::now(); scopeguard::guard(start, |last_wait_at| {...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/utils/src/error.rs
libs/utils/src/error.rs
/// Create a reporter for an error that outputs similar to [`anyhow::Error`] with Display with alternative setting. /// /// It can be used with `anyhow::Error` as well. /// /// Why would one use this instead of converting to `anyhow::Error` on the spot? Because /// anyhow::Error would also capture a stacktrace on the s...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/utils/src/serde_regex.rs
libs/utils/src/serde_regex.rs
//! A `serde::{Deserialize,Serialize}` type for regexes. use std::ops::Deref; #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] #[serde(transparent)] pub struct Regex( #[serde( deserialize_with = "deserialize_regex", serialize_with = "serialize_regex" )] regex::Regex, ); fn de...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/utils/src/span.rs
libs/utils/src/span.rs
//! Tracing span helpers. /// Records the given fields in the current span, as a single call. The fields must already have /// been declared for the span (typically with empty values). #[macro_export] macro_rules! span_record { ($($tokens:tt)*) => {$crate::span_record_in!(::tracing::Span::current(), $($tokens)*)};...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/utils/src/auth.rs
libs/utils/src/auth.rs
// For details about authentication see docs/authentication.md use std::borrow::Cow; use std::fmt::Display; use std::fs; use std::sync::Arc; use anyhow::Result; use arc_swap::ArcSwap; use camino::Utf8Path; use jsonwebtoken::{ Algorithm, DecodingKey, EncodingKey, Header, TokenData, Validation, decode, encode, }; u...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/utils/src/seqwait.rs
libs/utils/src/seqwait.rs
#![warn(missing_docs)] use std::cmp::{Eq, Ordering}; use std::collections::BinaryHeap; use std::mem; use std::sync::Mutex; use std::time::Duration; use tokio::sync::watch::{self, channel}; use tokio::time::timeout; /// An error happened while waiting for a number #[derive(Debug, PartialEq, Eq, thiserror::Error)] pub...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/utils/src/guard_arc_swap.rs
libs/utils/src/guard_arc_swap.rs
//! A wrapper around `ArcSwap` that ensures there is only one writer at a time and writes //! don't block reads. use std::sync::Arc; use arc_swap::ArcSwap; use tokio::sync::TryLockError; pub struct GuardArcSwap<T> { inner: ArcSwap<T>, guard: tokio::sync::Mutex<()>, } pub struct Guard<'a, T> { _guard: to...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/utils/src/lsn.rs
libs/utils/src/lsn.rs
#![warn(missing_docs)] use std::fmt; use std::ops::{Add, AddAssign}; use std::str::FromStr; use std::sync::atomic::{AtomicU64, Ordering}; use serde::de::Visitor; use serde::{Deserialize, Serialize}; use crate::seqwait::MonotonicCounter; /// Transaction log block size in bytes pub const XLOG_BLCKSZ: u32 = 8192; ///...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/utils/src/vec_map.rs
libs/utils/src/vec_map.rs
use std::alloc::Layout; use std::cmp::Ordering; use std::ops::RangeBounds; #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum VecMapOrdering { Greater, GreaterOrEqual, } /// Ordered map datastructure implemented in a Vec. /// /// Append only - can only add keys that are larger than the /// current max key....
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/utils/src/pageserver_feedback.rs
libs/utils/src/pageserver_feedback.rs
use std::time::{Duration, SystemTime}; use bytes::{Buf, BufMut, Bytes, BytesMut}; use pq_proto::{PG_EPOCH, read_cstr}; use serde::{Deserialize, Serialize}; use tracing::{trace, warn}; use crate::lsn::Lsn; /// Feedback pageserver sends to safekeeper and safekeeper resends to compute. /// /// Serialized in custom flex...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/utils/src/bin_ser.rs
libs/utils/src/bin_ser.rs
//! Utilities for binary serialization/deserialization. //! //! The [`BeSer`] trait allows us to define data structures //! that can match data structures that are sent over the wire //! in big-endian form with no packing. //! //! The [`LeSer`] trait does the same thing, in little-endian form. //! //! Note: you will ge...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/utils/src/ip_address.rs
libs/utils/src/ip_address.rs
use std::env::{VarError, var}; use std::error::Error; use std::net::IpAddr; use std::str::FromStr; /// Name of the environment variable containing the reachable IP address of the node. If set, the IP address contained in this /// environment variable is used as the reachable IP address of the pageserver or safekeeper ...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/utils/src/tracing_span_assert.rs
libs/utils/src/tracing_span_assert.rs
//! Assert that the current [`tracing::Span`] has a given set of fields. //! //! Can only produce meaningful positive results when tracing has been configured as in example. //! Absence of `tracing_error::ErrorLayer` is not detected yet. //! //! `#[cfg(test)]` code will get a pass when using the `check_fields_present` ...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/utils/src/logging.rs
libs/utils/src/logging.rs
use std::future::Future; use std::pin::Pin; use std::str::FromStr; use std::time::Duration; use anyhow::Context; use metrics::{IntCounter, IntCounterVec}; use once_cell::sync::Lazy; use strum_macros::{EnumString, VariantNames}; use tokio::time::Instant; use tracing::{info, warn}; /// Logs a critical error, similarly ...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/utils/src/fs_ext.rs
libs/utils/src/fs_ext.rs
/// Extensions to `std::fs` types. use std::{fs, io, path::Path}; use anyhow::Context; #[cfg(feature = "rename_noreplace")] mod rename_noreplace; #[cfg(feature = "rename_noreplace")] pub use rename_noreplace::rename_noreplace; pub trait PathExt { /// Returns an error if `self` is not a directory. fn is_empty...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/utils/src/linux_socket_ioctl.rs
libs/utils/src/linux_socket_ioctl.rs
//! Linux-specific socket ioctls. //! //! <https://elixir.bootlin.com/linux/v6.1.128/source/include/uapi/linux/sockios.h#L25-L27> use std::io; use std::mem::MaybeUninit; use std::os::fd::RawFd; use std::os::raw::c_int; use nix::libc::{FIONREAD, TIOCOUTQ}; unsafe fn do_ioctl(socket_fd: RawFd, cmd: nix::libc::Ioctl) -...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/utils/src/postgres_client.rs
libs/utils/src/postgres_client.rs
//! Postgres client connection code common to other crates (safekeeper and //! pageserver) which depends on tenant/timeline ids and thus not fitting into //! postgres_connection crate. use anyhow::Context; use postgres_connection::{PgConnectionConfig, parse_host_port}; use crate::id::TenantTimelineId; #[derive(Copy,...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/utils/src/signals.rs
libs/utils/src/signals.rs
pub use signal_hook::consts::TERM_SIGNALS; pub use signal_hook::consts::signal::*; use signal_hook::iterator::Signals; use tokio::signal::unix::{SignalKind, signal}; use tracing::info; pub enum Signal { Quit, Interrupt, Terminate, } impl Signal { pub fn name(&self) -> &'static str { match self...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/utils/src/leaky_bucket.rs
libs/utils/src/leaky_bucket.rs
//! This module implements the Generic Cell Rate Algorithm for a simplified //! version of the Leaky Bucket rate limiting system. //! //! # Leaky Bucket //! //! If the bucket is full, no new requests are allowed and are throttled/errored. //! If the bucket is partially full/empty, new requests are added to the bucket i...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/utils/src/metrics_collector.rs
libs/utils/src/metrics_collector.rs
use std::{ sync::{Arc, RwLock}, time::{Duration, Instant}, }; use metrics::{IntGauge, proto::MetricFamily, register_int_gauge}; use once_cell::sync::Lazy; pub static METRICS_STALE_MILLIS: Lazy<IntGauge> = Lazy::new(|| { register_int_gauge!( "metrics_metrics_stale_milliseconds", "The curren...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/utils/src/toml_edit_ext.rs
libs/utils/src/toml_edit_ext.rs
#[derive(Debug, thiserror::Error)] pub enum Error { #[error("item is not a document")] ItemIsNotADocument, #[error(transparent)] Serde(toml_edit::de::Error), } pub fn deserialize_item<T>(item: &toml_edit::Item) -> Result<T, Error> where T: serde::de::DeserializeOwned, { let document: toml_edit:...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/utils/src/circuit_breaker.rs
libs/utils/src/circuit_breaker.rs
use std::fmt::Display; use std::time::{Duration, Instant}; use metrics::IntCounter; /// Circuit breakers are for operations that are expensive and fallible. /// /// If a circuit breaker fails repeatedly, we will stop attempting it for some /// period of time, to avoid denial-of-service from retries, and /// to mitiga...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/utils/src/fs_ext/rename_noreplace.rs
libs/utils/src/fs_ext/rename_noreplace.rs
use nix::NixPath; /// Rename a file without replacing an existing file. /// /// This is a wrapper around platform-specific APIs. pub fn rename_noreplace<P1: ?Sized + NixPath, P2: ?Sized + NixPath>( src: &P1, dst: &P2, ) -> nix::Result<()> { { #[cfg(all(target_os = "linux", target_env = "gnu"))] ...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/utils/src/sync/heavier_once_cell.rs
libs/utils/src/sync/heavier_once_cell.rs
use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::{Arc, Mutex, MutexGuard}; use tokio::sync::Semaphore; /// Custom design like [`tokio::sync::OnceCell`] but using [`OwnedSemaphorePermit`] instead of /// `SemaphorePermit`. /// /// Allows use of `take` which does not require holding an outer mutex guard //...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/utils/src/sync/gate.rs
libs/utils/src/sync/gate.rs
use std::sync::Arc; use std::sync::atomic::{AtomicBool, Ordering}; use std::time::Duration; /// Gates are a concurrency helper, primarily used for implementing safe shutdown. /// /// Users of a resource call `enter()` to acquire a GateGuard, and the owner of /// the resource calls `close()` when they want to ensure th...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/utils/src/sync/duplex.rs
libs/utils/src/sync/duplex.rs
pub mod mpsc;
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/utils/src/sync/spsc_fold.rs
libs/utils/src/sync/spsc_fold.rs
use core::future::poll_fn; use core::task::Poll; use std::sync::{Arc, Mutex}; use diatomic_waker::DiatomicWaker; pub struct Sender<T> { state: Arc<Inner<T>>, } pub struct Receiver<T> { state: Arc<Inner<T>>, } struct Inner<T> { wake_receiver: DiatomicWaker, wake_sender: DiatomicWaker, value: Mute...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/utils/src/sync/duplex/mpsc.rs
libs/utils/src/sync/duplex/mpsc.rs
use tokio::sync::mpsc; /// A bi-directional channel. pub struct Duplex<S, R> { pub tx: mpsc::Sender<S>, pub rx: mpsc::Receiver<R>, } /// Creates a bi-directional channel. /// /// The channel will buffer up to the provided number of messages. Once the buffer is full, /// attempts to send new messages will wait...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/utils/tests/bin_ser_test.rs
libs/utils/tests/bin_ser_test.rs
use std::io::Read; use bytes::{Buf, BytesMut}; use hex_literal::hex; use serde::Deserialize; use utils::bin_ser::LeSer; #[derive(Debug, PartialEq, Eq, Deserialize)] pub struct HeaderData { magic: u16, info: u16, tli: u32, pageaddr: u64, len: u32, } // A manual implementation using BytesMut, just ...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/utils/benches/benchmarks.rs
libs/utils/benches/benchmarks.rs
use std::time::Duration; use criterion::{Bencher, Criterion, criterion_group, criterion_main}; use pprof::criterion::{Output, PProfProfiler}; use utils::id; use utils::logging::log_slow; // Register benchmarks with Criterion. criterion_group!( name = benches; config = Criterion::default().with_profiler(PProfP...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/neon-shmem/src/lib.rs
libs/neon-shmem/src/lib.rs
pub mod hash; pub mod shmem; pub mod sync;
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/neon-shmem/src/sync.rs
libs/neon-shmem/src/sync.rs
//! Simple utilities akin to what's in [`std::sync`] but designed to work with shared memory. use std::mem::MaybeUninit; use std::ptr::NonNull; use nix::errno::Errno; pub type RwLock<T> = lock_api::RwLock<PthreadRwLock, T>; pub type RwLockReadGuard<'a, T> = lock_api::RwLockReadGuard<'a, PthreadRwLock, T>; pub type R...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/neon-shmem/src/hash.rs
libs/neon-shmem/src/hash.rs
//! Resizable hash table implementation on top of byte-level storage (either a [`ShmemHandle`] or a fixed byte array). //! //! This hash table has two major components: the bucket array and the dictionary. Each bucket within the //! bucket array contains a `Option<(K, V)>` and an index of another bucket. In this way th...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false
neondatabase/neon
https://github.com/neondatabase/neon/blob/015b1c7cb3259a6fcd5039bc2bd46a462e163ae8/libs/neon-shmem/src/shmem.rs
libs/neon-shmem/src/shmem.rs
//! Dynamically resizable contiguous chunk of shared memory use std::num::NonZeroUsize; use std::os::fd::{AsFd, BorrowedFd, OwnedFd}; use std::ptr::NonNull; use std::sync::atomic::{AtomicUsize, Ordering}; use nix::errno::Errno; use nix::sys::mman::MapFlags; use nix::sys::mman::ProtFlags; use nix::sys::mman::mmap as n...
rust
Apache-2.0
015b1c7cb3259a6fcd5039bc2bd46a462e163ae8
2026-01-04T15:40:24.223849Z
false