-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds an internal API that allows creating temporary databases on demand for creating indexes on demand and deleting them.
- Loading branch information
Showing
19 changed files
with
495 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package database | ||
|
||
import ( | ||
"context" | ||
"sync" | ||
|
||
"github.com/genjidb/genji/engine" | ||
) | ||
|
||
const maxTransientPoolSize = 3 | ||
|
||
// TransientEnginePool manages a pool of transient engines. | ||
// It keeps a pool of maxTransientPoolSize engines. | ||
type TransientEnginePool struct { | ||
ng engine.Engine | ||
|
||
mu sync.Mutex | ||
pool []engine.Engine | ||
} | ||
|
||
// Get returns a free engine from the pool, if any. Otherwise it creates a new engine | ||
// and returns it. | ||
func (t *TransientEnginePool) Get(ctx context.Context) (engine.Engine, error) { | ||
t.mu.Lock() | ||
defer t.mu.Unlock() | ||
|
||
if len(t.pool) > 0 { | ||
ng := t.pool[len(t.pool)-1] | ||
t.pool = t.pool[:len(t.pool)-1] | ||
return ng, nil | ||
} | ||
|
||
return t.ng.NewTransientEngine(ctx) | ||
} | ||
|
||
// Release sets the engine for reuse. If the pool is full, it drops the given engine. | ||
func (t *TransientEnginePool) Release(ctx context.Context, ng engine.Engine) error { | ||
t.mu.Lock() | ||
defer t.mu.Unlock() | ||
|
||
if len(t.pool) >= maxTransientPoolSize { | ||
return ng.Drop(ctx) | ||
} | ||
|
||
t.pool = append(t.pool, ng) | ||
return nil | ||
} |
Oops, something went wrong.