Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

[DATASOURCE]: Persistent data handler update #478

Open
wants to merge 25 commits into
base: main
Choose a base branch
from

Conversation

amadolid
Copy link
Collaborator

@amadolid amadolid commented Jun 22, 2024

CHANGES:

!!! IMPORTANT !!!

  • As much as possible, Anchor classes should only communicate with Anchor classes too
  • Architype classes will act as view of Anchor on jaclang perspective
  • JacFeature implementations should be the bridge between Architype and Anchors

!!! --------- !!!

  • ObjectAnchor is now the description of the architype in datasource perspective.
  • datasource uses python's shelve.Shelf if specified. Backed up by memory.
  • Anchors now have synced and unsynced state.
  • Synced Anchors are either retrieve from the datasource or newly created from jaclang
  • Unsynced Anchors are either from reference id or from lazy loaded anchors from existing Synced Anchors
  • Saving Anchors will unsync non self reference to avoid recurssion
  • Access validation now support blacklist and whitelist approach
  • Access can be associated with read or write permission and also with root or node

!!! TO FOLLOW !!!

  • common operation to manipulate access

!!! --------- !!!

@amadolid amadolid mentioned this pull request Jun 22, 2024
jaclang/cli/cli.py Outdated Show resolved Hide resolved
jaclang/cli/cli.py Outdated Show resolved Hide resolved
jaclang/cli/cli.py Outdated Show resolved Hide resolved
jaclang/core/architype.py Outdated Show resolved Hide resolved
jaclang/core/architype.py Outdated Show resolved Hide resolved
jaclang/core/memory.py Outdated Show resolved Hide resolved
jaclang/core/memory.py Outdated Show resolved Hide resolved
jaclang/core/architype.py Outdated Show resolved Hide resolved
jaclang/core/architype.py Outdated Show resolved Hide resolved
jaclang/plugin/tests/test_jaseci.py Show resolved Hide resolved
jaclang/core/architype.py Outdated Show resolved Hide resolved
jaclang/core/architype.py Outdated Show resolved Hide resolved
@amadolid amadolid force-pushed the enhancements/persistent-v2 branch from 715c00a to d677938 Compare June 26, 2024 18:14
@amadolid amadolid requested a review from ypkang June 27, 2024 14:38
jaclang/core/architype.py Outdated Show resolved Hide resolved
jaclang/cli/cli.py Outdated Show resolved Hide resolved
jaclang/core/architype.py Outdated Show resolved Hide resolved
jaclang/core/architype.py Outdated Show resolved Hide resolved
jaclang/core/architype.py Outdated Show resolved Hide resolved
jaclang/core/architype.py Outdated Show resolved Hide resolved
jaclang/core/memory.py Outdated Show resolved Hide resolved
jaclang/core/memory.py Outdated Show resolved Hide resolved
@amadolid amadolid force-pushed the enhancements/persistent-v2 branch from 0511d22 to 770d8b5 Compare June 27, 2024 18:11
@amadolid amadolid requested a review from ypkang June 27, 2024 18:11
@amadolid amadolid force-pushed the enhancements/persistent-v2 branch 5 times, most recently from ab10a4e to a70412a Compare July 3, 2024 20:02
jaclang/core/architype.py Outdated Show resolved Hide resolved
jaclang/core/architype.py Outdated Show resolved Hide resolved
jaclang/core/memory.py Outdated Show resolved Hide resolved
jaclang/core/memory.py Outdated Show resolved Hide resolved
@amadolid amadolid requested a review from ypkang July 8, 2024 07:14
@amadolid amadolid force-pushed the enhancements/persistent-v2 branch 2 times, most recently from bad20f1 to 30232ce Compare July 12, 2024 12:30
ypkang
ypkang previously approved these changes Jul 12, 2024
Copy link
Contributor

@ypkang ypkang left a comment

Choose a reason for hiding this comment

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

I am okay with merging this. @marsninja if you sign off, we can 🚢 this.

@amadolid amadolid force-pushed the enhancements/persistent-v2 branch 4 times, most recently from f611dbc to 0e8e210 Compare July 15, 2024 15:37
jaclang/cli/cli.py Outdated Show resolved Hide resolved
jaclang/cli/cli.py Outdated Show resolved Hide resolved
jaclang/core/context.py Outdated Show resolved Hide resolved
jaclang/cli/cli.py Outdated Show resolved Hide resolved
jaclang/compiler/constant.py Outdated Show resolved Hide resolved
jaclang/plugin/default.py Show resolved Hide resolved
jaclang/cli/cli.py Outdated Show resolved Hide resolved
jaclang/cli/cli.py Outdated Show resolved Hide resolved
jaclang/cli/cli.py Outdated Show resolved Hide resolved
jaclang/compiler/constant.py Outdated Show resolved Hide resolved
@amadolid amadolid force-pushed the enhancements/persistent-v2 branch from 909c47c to a1f032b Compare July 18, 2024 15:07
@amadolid amadolid requested review from marsninja and ypkang July 18, 2024 15:08
@amadolid amadolid force-pushed the enhancements/persistent-v2 branch from e988be6 to 410bebb Compare July 18, 2024 15:49
@amadolid amadolid force-pushed the enhancements/persistent-v2 branch from 235c9cc to 58ab554 Compare August 14, 2024 04:24
@amadolid amadolid force-pushed the enhancements/persistent-v2 branch from 0f4e5e4 to 337e394 Compare August 14, 2024 06:03
@amadolid amadolid force-pushed the enhancements/persistent-v2 branch from 337e394 to 2d7b101 Compare August 14, 2024 07:28
@amadolid amadolid force-pushed the enhancements/persistent-v2 branch from 4eca7b4 to 03dbf72 Compare August 14, 2024 08:39
@amadolid amadolid force-pushed the enhancements/persistent-v2 branch from 4895d09 to d75fc1d Compare August 14, 2024 13:01
return super().setUp()

def test_import_basic_python(self) -> None:
"""Test basic self loading."""
Jac.context().init_memory(base_path=self.fixture_abs_path(__file__))
ExecutionContext.create(base_path=self.fixture_abs_path(__file__))
Copy link
Contributor

@ypkang ypkang Aug 14, 2024

Choose a reason for hiding this comment

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

We should get the context from the plugin, right? just like the rest of the codebase?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

will update

return Jac.context().mem
def current_context() -> ExecutionContext:
"""Get current execution context."""
return ExecutionContext.get()
Copy link
Contributor

@ypkang ypkang Aug 14, 2024

Choose a reason for hiding this comment

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

I guess the new_context vs current_context is to handle the difference between jac run via CLI and API request handling? Do we need to handle it explicitly like this? I think the ContextVar is either per thread or per task (in the case of asyncio). so it will automatically be a new one for new request.

From chatgpt

Yes, `ContextVar` in Python is designed to maintain context-specific data, and it behaves differently depending on the concurrency model.

- **Thread-based concurrency:** In a traditional thread-based model, each thread has its own separate context, so `ContextVar` instances are indeed per-thread. Each thread will have its own independent value for a `ContextVar`, meaning changes to a `ContextVar` in one thread will not affect the value in another thread.

- **Async concurrency (using `asyncio`):** In an asynchronous model, `ContextVar` is per-task. Each `asyncio` task has its own context, and changes to a `ContextVar` in one task will not affect the value in another task.

This design ensures that `ContextVar` provides isolation across threads and tasks, making it useful for managing context-specific data in concurrent programming.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

my assumptions is context should only be created per request/task and can only be read or update afterwards

in jaclang perspective,
new_context should be triggered only on cli

while current_context is for language level

@amadolid amadolid requested a review from ypkang August 15, 2024 03:35
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants