Skip to content

Commit

Permalink
Merge branch 'master' into watch
Browse files Browse the repository at this point in the history
  • Loading branch information
JyotinderSingh committed Oct 7, 2024
2 parents 22527eb + aaf7987 commit b1fa7b4
Show file tree
Hide file tree
Showing 25 changed files with 948 additions and 376 deletions.
15 changes: 11 additions & 4 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ type Config struct {
EvictionRatio float64 `mapstructure:"evictionratio"`
KeysLimit int `mapstructure:"keyslimit"`
AOFFile string `mapstructure:"aoffile"`
PersistenceEnabled bool `mapstructure:"persistenceenabled"`
WriteAOFOnCleanup bool `mapstructure:"writeaofoncleanup"`
LFULogFactor int `mapstructure:"lfulogfactor"`
LogLevel string `mapstructure:"loglevel"`
PrettyPrintLogs bool `mapstructure:"prettyprintlogs"`
EnableMultiThreading bool `mapstructure:"enablemultithreading"`
StoreMapInitSize int `mapstructure:"storemapinitsize"`
WatchChanBufSize int `mapstructure:"watchchanbufsize"`
} `mapstructure:"server"`
Auth struct {
UserName string `mapstructure:"username"`
Expand Down Expand Up @@ -99,34 +99,34 @@ var baseConfig = Config{
EvictionRatio float64 `mapstructure:"evictionratio"`
KeysLimit int `mapstructure:"keyslimit"`
AOFFile string `mapstructure:"aoffile"`
PersistenceEnabled bool `mapstructure:"persistenceenabled"`
WriteAOFOnCleanup bool `mapstructure:"writeaofoncleanup"`
LFULogFactor int `mapstructure:"lfulogfactor"`
LogLevel string `mapstructure:"loglevel"`
PrettyPrintLogs bool `mapstructure:"prettyprintlogs"`
EnableMultiThreading bool `mapstructure:"enablemultithreading"`
StoreMapInitSize int `mapstructure:"storemapinitsize"`
WatchChanBufSize int `mapstructure:"watchchanbufsize"`
}{
Addr: DefaultHost,
Port: DefaultPort,
KeepAlive: int32(300),
Timeout: int32(300),
MaxConn: int32(0),
ShardCronFrequency: 1 * time.Second,
ShardCronFrequency: 30 * time.Second,
MultiplexerPollTimeout: 100 * time.Millisecond,
MaxClients: int32(20000),
MaxMemory: 0,
EvictionPolicy: EvictAllKeysLFU,
EvictionRatio: 0.9,
KeysLimit: DefaultKeysLimit,
AOFFile: "./dice-master.aof",
PersistenceEnabled: true,
WriteAOFOnCleanup: false,
LFULogFactor: 10,
LogLevel: "info",
PrettyPrintLogs: false,
EnableMultiThreading: false,
StoreMapInitSize: 1024000,
WatchChanBufSize: 20000,
},
Auth: struct {
UserName string `mapstructure:"username"`
Expand Down Expand Up @@ -305,7 +305,14 @@ func mergeFlagsWithConfig() {

// This function checks if the config file is present or not at ConfigFileLocation
func isConfigFilePresent() bool {
// If config file present in current directory use it
if _, err := os.Stat(filepath.Join(".", DefaultConfigName)); err == nil {
FileLocation = filepath.Join(".", DefaultConfigName)
return true
}

_, err := os.Stat(FileLocation)

return err == nil
}

Expand Down
31 changes: 31 additions & 0 deletions dice.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[Server]
Addr = '0.0.0.0'
Port = 7379
KeepAlive = 300
Timeout = 300
MaxConn = 0
# Value in nanoseconds (30 seconds)
ShardCronFrequency = 30000000000
# Value in nanoseconds (100 ms/0.1 seconds)
MultiplexerPollTimeout = 100000000
MaxClients = 20000
MaxMemory = 0
EvictionPolicy = 'allkeys-lfu'
EvictionRatio = 0.4
KeysLimit = 100000
AOFFile = './dice-master.aof'
WriteAOFOnCleanup = false
LFULogFactor = 10
LogLevel = 'info'
PrettyPrintLogs = false
EnableMultiThreading = false
StoreMapInitSize = 10240
WatchChanBufSize = 20000

[Auth]
UserName = 'dice'
Password = ''

[Network]
IOBufferLength = 512
IOBufferLengthMAX = 51200
46 changes: 33 additions & 13 deletions docs/src/content/docs/commands/AUTH.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@ AUTH password

## Parameters

- `password` (string): The password that you have set for the DiceDB server. This is a required parameter for the `AUTH` command. If the password is correct, the command will return a success response; if it is incorrect, an error will be raised.
| Parameter | Description | Type | Required |
|-----------|---------------------------------------------------------------------------|---------|----------|
| `password`| The password that you have set for the DiceDB server. | String | Yes |

## Return Value
## Return values

- On success: The command returns the string `OK`, indicating that the authentication was successful.
- On failure: If the authentication fails (due to an incorrect password), it raises an error indicating the failure reason.
| Condition | Return Value |
|------------------------------------------------|---------------------------------------------------|
| Authentication is successful | `OK` |
| Syntax or specified constraints are invalid | error |

## Behaviour

Expand All @@ -32,42 +36,58 @@ When the `AUTH` command is executed, DiceDB will perform the following steps:

Once authenticated, the client can execute commands on the DiceDB server that require authentication. If a client attempts to send commands without being authenticated (and while authentication is required), DiceDB will respond with an error for unauthorized access.

## Errors

1. `(error) WRONGPASS invalid username-password pair or user is disabled`: This error occurs if the password provided to the `AUTH` command does not match the configured password of the DiceDB server. The client will not be granted access unless the correct password is provided.

2. `(error) NOAUTH Authentication required`: This error occurs when a client attempts to execute a command without authenticating first. The client must use the `AUTH` command to authenticate before executing any other commands.

3. `(error) ERR AUTH <password> called without any password configured for the default user. Are you sure your configuration is correct?`: This error will be raised if the DiceDB server is not configured to use a password (i.e., the `requirepass` directive in the DiceDB.conf file is empty or commented out), and a client attempts to authenticate using the `AUTH` command.

## Example Usage

### Successful Authentication

In this example, after successfully typing the correct password, the DiceDB server responds with `OK`, indicating that the client is now authenticated and can execute further commands.

```bash
127.0.0.1:7379> AUTH your_secret_password
OK
```

In this example, after successfully typing the correct password, the DiceDB server responds with `OK`, indicating that the client is now authenticated and can execute further commands.

### Failed Authentication

In this example, the provided password is incorrect. As a result, the DiceDB server responds with an error indicating that the authentication has failed.

```bash
127.0.0.1:7379> AUTH incorrect_password
(error) WRONGPASS invalid username-password pair or user is disabled
```

In this example, the provided password is incorrect. As a result, the DiceDB server responds with an error stating `(error) ERR invalid password`, indicating that the authentication has failed.

### Invoking commands without AUTH

In this example, when some other command is fired without doing `AUTH` then the above error is thrown denoting that authentication is required.

```bash
127.0.0.1:7379> GET x
(error) NOAUTH Authentication required
```

In this example, when some other command is fired without doing `AUTH` then the above error is thrown denoting that authentication is required.
### Invoking AUTH without configuring password

## Error Handling
In this example, when `AUTH` is fired without actually configuring the password for the DiceDB server, then the server returns an error indicating that no password is set or the configuration is incorrect.

The `AUTH` command may raise the following errors:
```bash
127.0.0.1:7379> AUTH incorrect_password
(error) ERR AUTH <password> called without any password configured for the default user. Are you sure your configuration is correct?
```

- `(error) ERR invalid password`: This error occurs if the password provided to the `AUTH` command does not match the configured password of the DiceDB server. The client will not be granted access unless the correct password is provided.
### Invalid usage

- `(error) ERR Client sent AUTH but no password is set`: This error will be raised if the DiceDB server is not configured to use a password (i.e., the `requirepass` directive in the DiceDB.conf file is empty or commented out), and a client attempts to authenticate using the `AUTH` command.
```bash
127.0.0.1:7379> AUTH your_secret_password foo bar
(error) ERR wrong number of arguments for 'auth' command
```

### Additional Notes

Expand Down
68 changes: 21 additions & 47 deletions docs/src/content/docs/commands/BGREWRITEAOF.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,18 @@ description: The `BGREWRITEAOF` command in DiceDB is used to asynchronously rewr

The `BGREWRITEAOF` command in DiceDB is used to asynchronously rewrite the Append-Only File (AOF). This command triggers a background process that creates a new AOF file, which is a more compact and optimized version of the current AOF file. The new AOF file will contain the minimal set of commands needed to reconstruct the current dataset.

## Parameters
## Syntax

The `BGREWRITEAOF` command does not take any parameters.
```
BGREWRITEAOF
```

## Return Value
## Return values

- `Simple String Reply`: The command returns a simple string reply indicating the status of the operation.
- If the background rewrite operation is successfully started, the reply will be:
```
"Background append only file rewriting started"
```
- If the operation cannot be started because a previous `BGREWRITEAOF` operation is still in progress, the reply will be:
```
"Background append only file rewriting already in progress"
```
| Condition | Return Value |
|------------------------------------------------|---------------------------------------------------|
| Command is successful | `OK` |
| Syntax or specified constraints are invalid | error |

## Behaviour

Expand All @@ -30,45 +27,22 @@ When the `BGREWRITEAOF` command is issued, DiceDB performs the following steps:
3. `Swapping Files`: Once the temporary AOF file is fully written and synced to disk, the child process swaps the temporary file with the existing AOF file.
4. `Cleaning Up`: The child process exits, and the main DiceDB server continues to operate with the new, optimized AOF file.

## Example Usage
```sh
127.0.0.1:7379> BGREWRITEAOF
"Background append only file rewriting started"
```

In this example, the `BGREWRITEAOF` command is issued, and the server responds with a confirmation that the background rewrite process has started.
## Errors

## Error Handling
1. `Unable to create/write AOF file`:

### Errors

1. `Background Rewrite Already in Progress`:

- `Condition`: If a `BGREWRITEAOF` operation is already in progress when the command is issued again.
- `Error Message`:
```
"Background append only file rewriting already in progress"
```
- Error Message: `ERR AOF failed`
- Occurs when diceDB is unable to create or write into the AOF file

2. `Forking Error`:

- `Condition`: If DiceDB is unable to fork a new process due to system limitations or resource constraints.
- `Error Message`:
```
"ERR Can't fork"
```
3. `AOF Disabled`:
- `Condition`: If AOF is disabled in the DiceDB configuration.
- `Error Message`:
```
"ERR AOF is not enabled"
```
- Error Message: `ERR Fork failed`
- Occurs when diceDB is unable to fork a new process due to system limitations or resource constraints.

## Best Practices
## Example Usage

- `Regular Maintenance`: Schedule regular `BGREWRITEAOF` operations during off-peak hours to ensure the AOF file remains compact and optimized.
- `Monitor Resource Usage`: Be aware that the `BGREWRITEAOF` operation can be resource-intensive. Monitor CPU and memory usage to avoid potential performance degradation.
- `Backup Before Rewrite`: Consider taking a backup of the current AOF file before initiating a rewrite, especially in production environments.
### Basic Usage
```sh
127.0.0.1:7379> BGREWRITEAOF
OK
```
Loading

0 comments on commit b1fa7b4

Please sign in to comment.