Skip to content

Conversation

@jnmt
Copy link
Collaborator

@jnmt jnmt commented Nov 10, 2025

Description

This PR adds the functionality to create multiple asset namespaces on a single ScalarDL cluster, allowing users to use separate namespaces for assets.

As the first step of the namespace feature, this PR only adds the creation interface and service. Creation CLI and the new Ledger interface to use multiple namespaces will be added in other PRs. Also, the E2E tests will be added in a PR on the auditor side.

Related issues and/or PRs

N/A

Changes made

  • Add the namespace-creation request to the gRPC protocol.
  • Add the namespace-creation interface to the client service.
  • Add the namespace-creation logic

Checklist

The following is a best-effort checklist. If any items in this checklist are not applicable to this PR or are dependent on other, unmerged PRs, please still mark the checkboxes after you have read and understood each item.

  • I have commented my code, particularly in hard-to-understand areas.
  • I have updated the documentation to reflect the changes.
  • I have considered whether similar issues could occur in other products, components, or modules if this PR is for bug fixes.
  • Any remaining open issues linked to this PR are documented and up-to-date (Jira, GitHub, etc.).
  • Tests (unit, integration, etc.) have been added for the changes.
  • My changes generate no new warnings.
  • Any dependent changes in other PRs have been merged and published.

Additional notes (optional)

N/A

Release notes

Added namespace creation functionality.

Copilot AI review requested due to automatic review settings November 10, 2025 05:25
@gemini-code-assist
Copy link

Summary of Changes

Hello @jnmt, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request delivers a significant new capability: the ability to create and manage namespaces. This feature provides a structured way to partition and isolate resources within the system, enhancing multi-tenancy and data organization. The changes span across the client, common, and ledger modules, introducing new APIs, robust server-side logic, and updated database interactions to support this functionality. It ensures that namespace creation is validated, handled correctly, and integrated seamlessly with the existing architecture.

Highlights

  • Namespace Creation Feature: Introduced a new feature allowing users to create namespaces within the system, enabling better organization and isolation of data and contracts.
  • Client-side API: Added new client-side APIs for initiating namespace creation requests, including methods for both string and serialized binary inputs.
  • Server-side Implementation: Implemented the core server-side logic for namespace creation, involving new NamespaceRegistry and NamespaceManager components to handle database interactions and name validation.
  • Error Handling and Validation: Integrated new error codes and validation logic to ensure proper namespace naming conventions and to handle cases where a namespace already exists or creation fails.
  • ScalarDB Integration: Updated the ScalarDB integration layer to dynamically create necessary tables for new namespaces and refactored dependency injection to use StorageFactory and TransactionFactory.
  • Comprehensive Testing: Added extensive unit and integration tests for the new namespace creation functionality, covering various scenarios including valid/invalid inputs and error conditions.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a significant new feature for namespace creation, touching multiple components across the client and ledger. The implementation is generally well-structured, with good test coverage for the new functionality. The refactoring in LedgerModule to use factories and multibindings for TableMetadataProvider is a solid improvement for dependency injection and extensibility. However, I've identified a critical race condition in the namespace creation logic that should be addressed to ensure atomicity. I've also included a minor suggestion to improve exception handling. Overall, this is a good contribution.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request implements namespace creation functionality for ScalarDL, allowing clients to create isolated namespaces for organizing contracts, functions, and other resources. The implementation adds gRPC endpoints, validation logic, and comprehensive test coverage across the ledger, client, and RPC layers.

  • Adds createNamespace RPC methods to LedgerPrivileged, AuditorPrivileged, and GatewayPrivileged services
  • Implements namespace name validation requiring alphabetic start and alphanumeric/underscore characters
  • Extends client APIs to support namespace creation in both CLIENT and INTERMEDIARY modes

Reviewed Changes

Copilot reviewed 40 out of 40 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
rpc/src/main/proto/scalar.proto Adds createNamespace RPC method and NamespaceCreationRequest message definition
ledger/src/main/java/com/scalar/dl/ledger/namespace/NamespaceManager.java Implements namespace validation and creation logic
ledger/src/main/java/com/scalar/dl/ledger/database/scalardb/AbstractScalarNamespaceRegistry.java Handles database namespace and table creation operations
ledger/src/main/java/com/scalar/dl/ledger/service/BaseService.java Adds namespace creation service method
ledger/src/main/java/com/scalar/dl/ledger/service/LedgerModule.java Updates dependency injection configuration for namespace functionality
client/src/main/java/com/scalar/dl/client/service/ClientService.java Adds public API for namespace creation
common/src/main/java/com/scalar/dl/ledger/error/CommonError.java Defines error codes for namespace operations
ledger/src/test/java/com/scalar/dl/ledger/namespace/NamespaceManagerTest.java Comprehensive test coverage for namespace validation
ledger/src/test/java/com/scalar/dl/ledger/database/scalardb/LedgerNamespaceRegistryTest.java Tests database namespace creation operations

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@jnmt jnmt self-assigned this Nov 10, 2025
@jnmt jnmt added the enhancement New feature or request label Nov 10, 2025
Copy link
Member

@josh-wong josh-wong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you!🙇🏻‍♂️

Comment on lines +101 to +108
Retry.decorateRunnable(
retry,
() -> {
createNamespaceManagementTable();
createNamespace(namespace);
addNamespaceEntry(namespace);
})
.run();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The retry logic is introduced mainly for Cassandra environments. Cassandra client sessions (storage, storageAdmin, transactionAdmin) have a delay to sync the namespace/table metadata with each other when creating a namespace/table, and often see "namespace/table not found" errors.

Comment on lines +124 to +125
// this sleep can be removed after negative cache is disabled in ScalarDB
Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, ScalarDB caches an empty result (negative cache) when a specified table is not found (e.g., due to the metadata sync delay mentioned above). It takes 60 seconds by default to expire, and users cannot create the namespace during that time. So, we would like to avoid it.

But, after the negative cache is disabled in ScalarDB, this delay/sleep can be achieved through the retry logic. Since sleep here is unnecessary and inefficient for other underlying storage, remove it after the fixed ScalarDB version is released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants