Repository: influxdata/influxdb
File: influxdb3_wal/src/object_store.rs (Rust)

Code before:
        debug!(
            ?all_paths,
            ">>> test: all paths in object store after removal"
        );

        assert!(object_store.get(&path1).await.ok().is_some());
        assert!(object_store.get(&path2).await.ok().is_some());

        // now add 3rd snapshot
        let snapshot_details = SnapshotDetails {
            snapshot_sequence_number: SnapshotSequenceNumber::new(3),
            end_time_marker: 30,
            // snapshot size is 1, so we just snapshotted to a single file
            first_wal_sequence_number: WalFileSequenceNumber::new(3),
            last_wal_sequence_number: WalFileSequenceNumber::new(3),
            forced: false,
        };

        // add that wal file to obj store
        object_store
            .put(&path3, PutPayload::from_static(b"foo"))
            .await
            .unwrap();

        let snapshot_permit = Arc::new(Semaphore::new(1)).acquire_owned().await.unwrap();
        // this will not delete any files - we've added the 3rd file still no deletes
        wal.remove_snapshot_wal_files(snapshot_details, snapshot_permit)
            .await;

        let all_paths = load_all_wal_file_paths(Arc::clone(&object_store), "my_host".to_string())
            .await
            .unwrap();

        debug!(
            ?all_paths,
            ">>> test: all paths in object store after removal"
        );

        let err = object_store.get(&path1).await.err().unwrap();

        assert!(matches!(
            err,
            object_store::Error::NotFound { path: _, source: _ }
        ));
        assert!(object_store.get(&path2).await.ok().is_some());
        assert!(object_store.get(&path3).await.ok().is_some());
    }

    #[test_log::test(tokio::test)]
    async fn test_wal_file_removal_after_snapshot_worked_out_example() {
        // Say we snapshot every 5 files, and we always want to keep around at least 10 snapshotted files.

Review comment (bug):
This comment says that no files will be deleted, but at line 1647 the test asserts that `path1` is no longer in the object store so I'm a little confused as to what causes that path to be deleted. Is the comment wrong or am I missing something?

Code after:
        debug!(
            ?all_paths,
            ">>> test: all paths in object store after removal"
        );

        assert!(object_store.get(&path1).await.ok().is_some());
        assert!(object_store.get(&path2).await.ok().is_some());

        // now add 3rd snapshot
        let snapshot_details = SnapshotDetails {
            snapshot_sequence_number: SnapshotSequenceNumber::new(3),
            end_time_marker: 30,
            // snapshot size is 1, so we just snapshotted to a single file
            first_wal_sequence_number: WalFileSequenceNumber::new(3),
            last_wal_sequence_number: WalFileSequenceNumber::new(3),
            forced: false,
        };

        // add that wal file to obj store
        object_store
            .put(&path3, PutPayload::from_static(b"foo"))
            .await
            .unwrap();

        let snapshot_permit = Arc::new(Semaphore::new(1)).acquire_owned().await.unwrap();
        wal.remove_snapshot_wal_files(snapshot_details, snapshot_permit)
            .await;

        let all_paths = load_all_wal_file_paths(Arc::clone(&object_store), "my_host".to_string())
            .await
            .unwrap();

        debug!(
            ?all_paths,
            ">>> test: all paths in object store after removal"
        );

        let err = object_store.get(&path1).await.err().unwrap();

        assert!(matches!(
            err,
            object_store::Error::NotFound { path: _, source: _ }
        ));
        assert!(object_store.get(&path2).await.ok().is_some());
        assert!(object_store.get(&path3).await.ok().is_some());
    }

    #[test_log::test(tokio::test)]
    async fn test_wal_file_removal_after_snapshot_worked_out_example() {
        // Say we snapshot every 5 files, and we always want to keep around at least 10 snapshotted files.
        // Then say we're currently in this state