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

multi: Add cache layer #660

Merged
merged 11 commits into from Feb 8, 2019
Merged

multi: Add cache layer #660

merged 11 commits into from Feb 8, 2019

Conversation

lukebp
Copy link
Member

@lukebp lukebp commented Jan 7, 2019

Closes #546.

This PR adds a cache layer to politeiad and politeiawww. The politeiad git repositories serve as the source of truth for proposal data and a CockroachDB database acts as a cache for proposal data.

The cache is not required if you're running just politeiad. politeiad has the cache disable by default. If you're running the full politeia stack, politeiad and politeiawww, running the cache is required.

politeiad has read and write access to the cache. politeiawww has only read access to the cache. The flow of data is as follows:

  1. politeiawww receives a command from a user
  2. politeiawww creates a politeiad request for the command and sends it
  3. politeiad writes the command data to the git repository and updates the cache
  4. politeiad returns a response to politeiawww
  5. politeiawww reads the cache if needed
  6. politeiawww returns a response to the user

The cache will build itself automatically on startup if it hasn't been built yet or it the version changes. You can also force a cache rebuild by using the --buildcache flag when starting politeiad.

This PR does not attempt to optimize the cache performance at all. Bottlenecks will be identified and performance will be optimized in a future PR.

Other major changes this PR makes:

  • politeiad API responses trimmed for SetUnvettedStatus, SetVettedStatus, and UpdateRecord. These responses no longer return the full record. They only return the status of the update.
  • The following decred plugin commands were added: votedetails, getcomment, commentlikes, and inventory.
  • politeiawww inventory completely removed
  • politeiawww proposal tests were re-written due to their reliance on the inventory

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
@sndurkin
Copy link
Contributor

sndurkin commented Jan 14, 2019

Is this change going to be backward compatible for non-politeiawww clients of politeiad?

@lukebp
Copy link
Member Author

lukebp commented Jan 14, 2019

@sndurkin the politeiad getvetted and getunvetted endpoints have been left in unaltered. The politeiad endpoints that write data to the git repos have had their responses trimmed to only include the status of the operation, not the record data itself.

The way its written now, a cache must be used with politeiad. It could be updated to have some type of --skipcache option that would allow you to run politeiad without a cache if that's a desirable feature.

Edit: the cache now defaults to being disabled on politeiad. The enablecache config setting must be used in order to enable the cache.

This commit adds a cache layer to politeiad and politeiawww.  The
politeiad git repositories serve as the source of truth for proposal
data and a CockroachDB database acts as a cache for proposal data.

politeiad has read and write access to the cache.  politeiawww has only
read access to the cache.  The flow of data is as follows:

1. politeiawww receives a command from a user
2. politeiawww creates a politeiad request for the command and sends it
3. politeiad writes the command data to the git repository and updates
   the cache
4. politeiad returns a response to politeiawww
5. politeiawww reads the cache if needed
6. politeiawww returns a response to the user

The cache is automatically rebuilt on cache version change.  You can
also force the cache to rebuilt by using the flag --buildcache on
politeiad startup.

The politeiad record and all record metadata has been removed from the
politeiawww inventory.  The only thing left in the inventory is decred
plugin data.  The decred plugin data will be added to the cache and
removed from the inventory in a future PR.

Since this commit touched so much of the code for the `/proposals`
endpoints, I began cleaning up `backend.go` and moving the updated
`/proposals` enpoint code to `proposals.go`.

I had to delete all of the tests that relied on the proposal record in
the inventory.  I re-wrote most of these tests in `proposals_test.go`.
Copy link
Member

@marcopeereboom marcopeereboom left a comment

Choose a reason for hiding this comment

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

I love this! Just a couple of nits.

// InventoryReply returns the decred plugin inventory.
type InventoryReply struct {
Comments []Comment `json:"comments"` // Comments
CommentLikes []LikeComment `json:"commentlikes"` // Comment likes
Copy link
Member

Choose a reason for hiding this comment

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

The asymmetry is bothering my OCD!

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

decredPluginJournals = "journals"
decredPluginIdentity = "fullidentity"
decredPluginJournals = "journals"
decredPluginInventoryCmd = "inventorycmd"
Copy link
Member

Choose a reason for hiding this comment

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

Why is this postfixed cmd?

Copy link
Member Author

Choose a reason for hiding this comment

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

It doesn't need to be. It has been shortened to "inventory".

politeiad/backend/gitbe/decred.go Show resolved Hide resolved
politeiad/cache/cache.go Show resolved Hide resolved
Settings []PluginSetting // Settings
}

// PluginDriver is the interface that all cache plugins must implement.
Copy link
Member

Choose a reason for hiding this comment

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

Explain what this does and why it exists.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added doco.

}
defer rows.Close()

records := make([]Record, 0, 1024) // PNOOMA
Copy link
Member

Choose a reason for hiding this comment

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

Glad you picked up on the PNOOMA development methodology!

politeiad/politeiad.go Show resolved Hide resolved
politeiawww/api/v1/v1.go Show resolved Hide resolved
@marcopeereboom marcopeereboom merged commit 076c4f8 into decred:master Feb 8, 2019
@lukebp lukebp deleted the cache branch March 3, 2019 22:42
vibros68 pushed a commit to vibros68/politeia that referenced this pull request Aug 17, 2021
* fix prop display

* clear warning
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.

None yet

5 participants