Skip to content

Commit

Permalink
Add APIs for recording_id and application_id (rerun-io#7642)
Browse files Browse the repository at this point in the history
### What
- Resolves: rerun-io#7628

Needed to track the StoreId on the ChunkStore as well.

### Checklist
* [x] I have read and agree to [Contributor
Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and
the [Code of
Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md)
* [x] I've included a screenshot or gif (if applicable)
* [x] I have tested the web demo (if applicable):
* Using examples from latest `main` build:
[rerun.io/viewer](https://rerun.io/viewer/pr/7642?manifest_url=https://app.rerun.io/version/main/examples_manifest.json)
* Using full set of examples from `nightly` build:
[rerun.io/viewer](https://rerun.io/viewer/pr/7642?manifest_url=https://app.rerun.io/version/nightly/examples_manifest.json)
* [x] The PR title and labels are set such as to maximize their
usefulness for the next release's CHANGELOG
* [x] If applicable, add a new check to the [release
checklist](https://github.com/rerun-io/rerun/blob/main/tests/python/release_checklist)!
* [x] If have noted any breaking changes to the log API in
`CHANGELOG.md` and the migration guide

- [PR Build Summary](https://build.rerun.io/pr/7642)
- [Recent benchmark results](https://build.rerun.io/graphs/crates.html)
- [Wasm size tracking](https://build.rerun.io/graphs/sizes.html)

To run all checks from `main`, comment on the PR with `@rerun-bot
full-check`.
  • Loading branch information
jleibs authored Oct 8, 2024
1 parent 2728b05 commit 0acab6d
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 5 deletions.
1 change: 1 addition & 0 deletions crates/store/re_chunk_store/src/gc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ impl ChunkStore {

let Self {
id: _,
info: _,
config: _,
type_registry: _,
chunks_per_chunk_id,
Expand Down
24 changes: 20 additions & 4 deletions crates/store/re_chunk_store/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use arrow2::datatypes::DataType as ArrowDataType;
use nohash_hasher::IntMap;

use re_chunk::{Chunk, ChunkId, RowId, TransportChunk};
use re_log_types::{EntityPath, StoreId, TimeInt, Timeline};
use re_log_types::{EntityPath, StoreId, StoreInfo, TimeInt, Timeline};
use re_types_core::ComponentName;

use crate::{ChunkStoreChunkStats, ChunkStoreError, ChunkStoreResult};
Expand Down Expand Up @@ -292,6 +292,7 @@ pub struct ChunkStoreGeneration {
#[derive(Debug)]
pub struct ChunkStore {
pub(crate) id: StoreId,
pub(crate) info: Option<StoreInfo>,

/// The configuration of the chunk store (e.g. compaction settings).
pub(crate) config: ChunkStoreConfig,
Expand Down Expand Up @@ -366,6 +367,7 @@ impl Clone for ChunkStore {
fn clone(&self) -> Self {
Self {
id: self.id.clone(),
info: self.info.clone(),
config: self.config.clone(),
type_registry: self.type_registry.clone(),
chunks_per_chunk_id: self.chunks_per_chunk_id.clone(),
Expand All @@ -389,6 +391,7 @@ impl std::fmt::Display for ChunkStore {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let Self {
id,
info: _,
config,
type_registry: _,
chunks_per_chunk_id,
Expand Down Expand Up @@ -443,6 +446,7 @@ impl ChunkStore {
pub fn new(id: StoreId, config: ChunkStoreConfig) -> Self {
Self {
id,
info: None,
config,
type_registry: Default::default(),
chunk_ids_per_min_row_id: Default::default(),
Expand All @@ -464,6 +468,16 @@ impl ChunkStore {
&self.id
}

#[inline]
pub fn set_info(&mut self, info: StoreInfo) {
self.info = Some(info);
}

#[inline]
pub fn info(&self) -> Option<&StoreInfo> {
self.info.as_ref()
}

/// Return the current [`ChunkStoreGeneration`]. This can be used to determine whether the
/// database has been modified since the last time it was queried.
#[inline]
Expand Down Expand Up @@ -538,9 +552,11 @@ impl ChunkStore {
let msg = res.with_context(|| format!("couldn't decode message {path_to_rrd:?} "))?;
match msg {
re_log_types::LogMsg::SetStoreInfo(info) => {
stores
.entry(info.info.store_id.clone())
.or_insert_with(|| Self::new(info.info.store_id, store_config.clone()));
let store = stores.entry(info.info.store_id.clone()).or_insert_with(|| {
Self::new(info.info.store_id.clone(), store_config.clone())
});

store.set_info(info.info);
}

re_log_types::LogMsg::ArrowMsg(store_id, msg) => {
Expand Down
1 change: 1 addition & 0 deletions crates/store/re_chunk_store/src/writes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,7 @@ impl ChunkStore {

let Self {
id,
info: _,
config: _,
type_registry: _,
chunks_per_chunk_id,
Expand Down
2 changes: 2 additions & 0 deletions rerun_py/rerun_bindings/rerun_bindings.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class Recording:

def schema(self) -> Schema: ...
def view(self, index: str, contents: ViewContentsLike) -> RecordingView: ...
def recording_id(self) -> str: ...
def application_id(self) -> str: ...

class RRDArchive:
"""An archive loaded from an RRD, typically containing 1 or more recordings or blueprints."""
Expand Down
16 changes: 16 additions & 0 deletions rerun_py/src/dataframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,22 @@ impl PyRecording {
query_expression: query,
})
}

fn recording_id(&self) -> String {
self.store.id().as_str().to_owned()
}

fn application_id(&self) -> PyResult<String> {
Ok(self
.store
.info()
.ok_or(PyValueError::new_err(
"Recording is missing application id.",
))?
.application_id
.as_str()
.to_owned())
}
}

#[pyclass(frozen, name = "RRDArchive")]
Expand Down
10 changes: 9 additions & 1 deletion rerun_py/tests/unit/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@

import pathlib
import tempfile
import uuid

import pyarrow as pa
import rerun as rr

APP_ID = "rerun_example_test_recording"
RECORDING_ID = uuid.uuid4()


def test_load_recording() -> None:
with tempfile.TemporaryDirectory() as tmpdir:
Expand Down Expand Up @@ -41,7 +45,7 @@ def test_load_recording() -> None:

class TestDataframe:
def setup_method(self) -> None:
rr.init("rerun_example_test_recording")
rr.init(APP_ID, recording_id=RECORDING_ID)

rr.set_time_sequence("my_index", 1)
rr.log("points", rr.Points3D([[1, 2, 3], [4, 5, 6], [7, 8, 9]]))
Expand All @@ -55,6 +59,10 @@ def setup_method(self) -> None:

self.recording = rr.dataframe.load_recording(rrd)

def test_recording_info(self) -> None:
assert self.recording.application_id() == APP_ID
assert self.recording.recording_id() == str(RECORDING_ID)

def test_full_view(self) -> None:
view = self.recording.view(index="my_index", contents="points")

Expand Down

0 comments on commit 0acab6d

Please sign in to comment.