Skip to content

Commit

Permalink
Begin work on persistence and transaction systems.
Browse files Browse the repository at this point in the history
  • Loading branch information
GraphR00t committed May 18, 2024
1 parent 01ad065 commit aca05ac
Show file tree
Hide file tree
Showing 84 changed files with 1,419 additions and 15,521 deletions.
3 changes: 0 additions & 3 deletions internal/core/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ func (t *Tuple) IsEmpty(ctx *Context) bool {
}

func (obj *Object) Contains(ctx *Context, value Serializable) bool {
obj.waitForOtherTxsToTerminate(ctx, false)

closestState := ctx.MustGetClosestState()
obj._lock(closestState)
defer obj._unlock(closestState)
Expand Down Expand Up @@ -116,7 +114,6 @@ func (obj *Object) Contains(ctx *Context, value Serializable) bool {
}

func (obj *Object) IsEmpty(ctx *Context) bool {
obj.waitForOtherTxsToTerminate(ctx, false)

closestState := ctx.MustGetClosestState()
obj._lock(closestState)
Expand Down
4 changes: 0 additions & 4 deletions internal/core/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,10 +343,6 @@ func (o *Object) Migrate(ctx *Context, key Path, migration *FreeEntityMigrationA
panic(ErrUnreachable)
}

if o.txIsolator.currentWriteTx != nil {
panic(ErrUnreachable)
}

if ctx.GetTx() != nil {
panic(ErrUnreachable)
}
Expand Down
24 changes: 2 additions & 22 deletions internal/core/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ type additionalObjectFields struct {
//pendingChanges []pendingObjectEntryChange //only visible by the current read-write tx
//TODO: make sure the .IsEmpty and .Contains methods use them.

txIsolator StrongTransactionIsolator //TODO: replace with LiteTransactionIsolator

//Watching related fields

watchers *ValueWatchers
Expand Down Expand Up @@ -235,17 +233,6 @@ func (obj *Object) SmartUnlock(state *GlobalState) {
obj.lock.Unlock(state, obj, true)
}

func (obj *Object) waitForOtherTxsToTerminate(ctx *Context, requiredRunningTx bool) (currentTx *Transaction) {
if !obj.hasAdditionalFields() {
return
}
tx, err := obj.txIsolator.WaitForOtherTxsToTerminate(ctx, requiredRunningTx)
if err != nil {
panic(err)
}
return tx
}

func (obj *Object) Prop(ctx *Context, name string) Value {
return obj.prop(ctx, name, true)
}
Expand All @@ -255,7 +242,6 @@ func (obj *Object) PropNotStored(ctx *Context, name string) Value {
}

func (obj *Object) prop(ctx *Context, name string, stored bool) (returnedValue Value) {
obj.waitForOtherTxsToTerminate(ctx, !stored)

closestState := ctx.MustGetClosestState()
obj._lock(closestState)
Expand Down Expand Up @@ -318,8 +304,6 @@ func (obj *Object) SetProp(ctx *Context, name string, value Value) error {
return fmt.Errorf("value is not serializable")
}

tx := obj.waitForOtherTxsToTerminate(ctx, false)

closestState := ctx.MustGetClosestState()

if obj.IsShared() {
Expand Down Expand Up @@ -354,6 +338,8 @@ func (obj *Object) SetProp(ctx *Context, name string, value Value) error {
}
}

tx := ctx.GetTx()

//If the object is an entity and we are in a transaction we update the pending changes instead of directly mutating the entries.
//If there is already a change for the entry we update it, else we add a new change.
if tx != nil && obj.hasURL() {
Expand Down Expand Up @@ -491,7 +477,6 @@ func (obj *Object) SetProp(ctx *Context, name string, value Value) error {
}

func (obj *Object) PropertyNames(ctx *Context) []string {
obj.waitForOtherTxsToTerminate(ctx, false)

closestState := ctx.MustGetClosestState()
obj._lock(closestState)
Expand All @@ -500,7 +485,6 @@ func (obj *Object) PropertyNames(ctx *Context) []string {
}

func (obj *Object) HasProp(ctx *Context, name string) bool {
obj.waitForOtherTxsToTerminate(ctx, false)

closestState := ctx.MustGetClosestState()
obj._lock(closestState)
Expand All @@ -514,7 +498,6 @@ func (obj *Object) HasProp(ctx *Context, name string) bool {
}

func (obj *Object) HasPropValue(ctx *Context, value Value) bool {
obj.waitForOtherTxsToTerminate(ctx, false)

closestState := ctx.MustGetClosestState()
obj._lock(closestState)
Expand All @@ -533,7 +516,6 @@ func (obj *Object) EntryMap(ctx *Context) map[string]Serializable {
}

if ctx != nil {
obj.waitForOtherTxsToTerminate(ctx, false)

closestState := ctx.MustGetClosestState()
obj._lock(closestState)
Expand All @@ -560,7 +542,6 @@ func (obj *Object) ValueEntryMap(ctx *Context) map[string]Value {
}

if ctx != nil {
obj.waitForOtherTxsToTerminate(ctx, false)

closestState := ctx.MustGetClosestState()
obj._lock(closestState)
Expand Down Expand Up @@ -652,7 +633,6 @@ func (obj *Object) SetURLOnce(ctx *Context, u URL) error {
}

func (obj *Object) Keys(ctx *Context) []string {
obj.waitForOtherTxsToTerminate(ctx, false)

closestState := ctx.MustGetClosestState()
obj._lock(closestState)
Expand Down
12 changes: 6 additions & 6 deletions internal/core/object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,12 @@ func TestObject(t *testing.T) {
obj := NewObjectFromMap(ValMap{"a": Int(1)}, ctx1)
obj.Share(ctx1.MustGetClosestState())

// since context has no associated transaction a panic is expected
if !assert.Panics(t, func() {
obj.PropNotStored(ctx1, "a")
}) {
return
}
// // since context has no associated transaction a panic is expected
// if !assert.Panics(t, func() {
// obj.PropNotStored(ctx1, "a")
// }) {
// return
// }

ctx2 := NewContextWithEmptyState(ContextConfig{
Permissions: GetDefaultGlobalVarPermissions(),
Expand Down
247 changes: 0 additions & 247 deletions internal/core/transaction_isolation.go

This file was deleted.

0 comments on commit aca05ac

Please sign in to comment.