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

[#310] Persist sqlite to disk #321

Merged
merged 4 commits into from
Dec 29, 2017
Merged

[#310] Persist sqlite to disk #321

merged 4 commits into from
Dec 29, 2017

Conversation

evan2645
Copy link
Member

This PR exposes a file path configuration option for sqlite datastore. In order to do that, a number of changes were required:

  • Implement configuration load/reload logic in datastore plugin
  • Refactor migration logic to add automatic migration and remove bindata dependency
  • Light refactor of schema following bindata removal

If a file path is not configured, the plugin will default to an in-memory database. Fixes #310

Copy link
Member

@amartinezfayo amartinezfayo left a comment

Choose a reason for hiding this comment

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

Looks very good!
I have few comments.

@@ -3,4 +3,6 @@ pluginCmd = "plugin/server/datastore-sqlite/datastore-sqlite"
pluginChecksum = ""
enabled = true
pluginType = "DataStore"
pluginData {}
pluginData {
file_name = "./conf/server/spire.db"
Copy link
Member

Choose a reason for hiding this comment

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

I'm wondering if having this database file under the config folder would be confusing.
The nature of the data stored looks more like operational data rather than configuration settings.
Also, from an end-user perspective, I'm thinking if I see this file here, how do I know that belongs to the datastore-sqlite plugin? What if other server plugins use a database file in the future?

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed... I struggled a little trying to come up with the correct location for this.

I think we need a general directory for runtime file storage... use cases like attestation nonce come to mind. This seems like it may fit the bill as well... perhaps I'll create a top-level data directory, and stick it in there with a name like datastore_sqlite.db or datastore.sqlite3? Would that suffice?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, that looks good!

}
path = "file:" + path
Copy link
Member

Choose a reason for hiding this comment

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

Maybe is useful to log the path that is being used?

Copy link
Member Author

Choose a reason for hiding this comment

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

👍 will fix

@evan2645
Copy link
Member Author

@amartinezfayo pushed a commit to address your comments - let me know if that covers it or not. Thanks!

Copy link
Member

@amartinezfayo amartinezfayo left a comment

Choose a reason for hiding this comment

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

I think that we will need to create the folder of the data file if it doesn't exist.


db.LogMode(true)
log.Printf("opening sqlite database with path %s", path)
db, err := gorm.Open("sqlite3", path)
Copy link
Member

Choose a reason for hiding this comment

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

In case of a file path, I think that we will now need to check if the folder exists.
I guess that there will be an error here if you don't have the .data folder. We can automatically create the folder in that case at this point.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm hesitant to create directories if they don't exist, since it might be an error condition rather than an omission.

How about I create an empty .data dir and check it in?

Copy link
Member

Choose a reason for hiding this comment

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

💯 Yes, that's better.

Copy link
Member Author

Choose a reason for hiding this comment

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

@amartinezfayo fixed. Git automatically removes empty directories, so I put a placeholder file there.

Copy link
Member

@amartinezfayo amartinezfayo left a comment

Choose a reason for hiding this comment

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

LGTM!

@evan2645 evan2645 merged commit 156db7c into spiffe:master Dec 29, 2017
@evan2645 evan2645 deleted the persist-sqlite-to-disk branch December 29, 2017 18:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants