write dbstate, rotation logic