Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support modusDB instance per data directory #15

Closed
wants to merge 6 commits into from
Closed

Conversation

jairad26
Copy link
Member

@jairad26 jairad26 commented Nov 8, 2024

This PR adds support for multiple modusDB instances in a single process, as long as they each reference their own dataDirectory. This moves the dataDirectory field out of the config and into the DB layer, and removes the validate function & WithDataDir functions, since DataDir is a mandatory field, it is now moved into an argument on the New() function.

@jairad26 jairad26 changed the title Db per dir Support modusDB instance per data directory Nov 8, 2024
@mangalaman93
Copy link
Member

@jairad26 could you add a test for this? Because Dgraph uses global variables, I am not sure how this is working!

@jairad26 jairad26 enabled auto-merge (squash) November 11, 2024 14:56
@@ -56,8 +56,142 @@ func TestRestart(t *testing.T) {
require.NoError(t, db.DropAll(context.Background()))
}

func TestMultipleStartOnSameDir(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

This test seems to fail because we have global variables in Dgraph repo

func TestMultipleDBsDifferentDir(t *testing.T) {
	dataDir := t.TempDir()
	dataDir2 := t.TempDir()

	db1, err := modusdb.New(modusdb.NewDefaultConfig(), dataDir)
	require.NoError(t, err)
	defer func() { db1.Close() }()

	db2, err := modusdb.New(modusdb.NewDefaultConfig(), dataDir2)
	require.NoError(t, err)
	defer func() { db2.Close() }()

	_, err = db1.Mutate(context.Background(), []*api.Mutation{
		{
			Set: []*api.NQuad{
				{
					Namespace:   0,
					Subject:     "_:aman",
					Predicate:   "name",
					ObjectValue: &api.Value{Val: &api.Value_StrVal{StrVal: "A"}},
				},
			},
		},
	})
	require.NoError(t, err)

	_, err = db2.Mutate(context.Background(), []*api.Mutation{
		{
			Set: []*api.NQuad{
				{
					Namespace:   0,
					Subject:     "_:aman",
					Predicate:   "name",
					ObjectValue: &api.Value{Val: &api.Value_StrVal{StrVal: "B"}},
				},
			},
		},
	})
	require.NoError(t, err)

	query := `{
			me(func: has(name)) {
				name
			}
		}`
	qresp, err := db1.Query(context.Background(), query)
	require.NoError(t, err)
	require.JSONEq(t, `{"me":[{"name":"A"}]}`, string(qresp.GetJson()))

	// drop db1
	require.NoError(t, db1.DropAll(context.Background()))
}

@jairad26 jairad26 closed this Nov 12, 2024
auto-merge was automatically disabled November 12, 2024 23:10

Pull request was closed

@mangalaman93 mangalaman93 deleted the db-per-dir branch November 27, 2024 08:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants