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
Add daemon mode for wal-push command #1353
Conversation
a9f7e95
to
66c110d
Compare
af155a8
to
912cf6a
Compare
912cf6a
to
766a6e2
Compare
else | ||
echo "Error in WAL-G response" | ||
exit 1 | ||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also need to check that WAL has been archived correctly.
|
||
// daemonCmd represents the daemon archive command | ||
var daemonCmd = &cobra.Command{ | ||
Use: "daemon daemon_socket_path", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add some information about this command to the documentation.
func (h *ArchiveMessageHandler) Handle(messageBody []byte) error { | ||
err := messageValidation(messageBody) | ||
if err != nil { | ||
tracelog.ErrorLogger.Printf("Incorrect message: %v\n", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can just log the error in the upper level.
Here you can use the fmt.Errorf("msg: %w", err) to wrap error with some message.
For example:
if err != nil {
return fmt.Errorf("message validation failed: %w", err)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same issue in other places below.
tracelog.ErrorLogger.Fatal("Error on listening socket:", err) | ||
} | ||
for { | ||
fd, err := l.Accept() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if we would want to terminate the running daemon?
I suggest to add the signal listener and listend for SIGTERM
to perform a graceful shutdown. But looks like it is a feature for the next PR, not for the MVP.
messageType, messageBody, err := messageReader.Next() | ||
if err != nil { | ||
tracelog.ErrorLogger.Printf("Failed to read message from client %s, err: %v\n", c.RemoteAddr(), err) | ||
_, _ = c.Write([]byte{'E'}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do not ignore the possible errors
messageHandler := GetMessageHandler(messageType, c, uploader) | ||
if messageHandler == nil { | ||
tracelog.ErrorLogger.Printf("Unexpected message type: %s", string(messageType)) | ||
_, _ = c.Write([]byte{'E'}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Create these mesage types as well:
type ErrorType SocketMessageType = 'E'
type ... SocketMessageType = 'F'
type ... SocketMessageType = 'O'
...
} | ||
|
||
func messageValidation(messageBody []byte) error { | ||
if len(messageBody) < 24 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, we archive not only WALs but other files with length other than 24.
I think we can remove this validation.
…tion; test listing.
8a191d3
to
6fedfec
Compare
Database name
postgresql15
Pull request description
Added daemon command for archiving wal segments