Monday, January 20, 2020

Date modified timestamp problems on a Linux SMB share

I discovered an annoying issue recently related to our switch from a Windows-based file server to a Linux-based one.

The computer lab in the library where I work uses an Access database to record registration information of students who sign up for the adult computer classes that the lab runs. Several years ago, I wrote a Java Swing application that sits on top of this database to make the registration process faster and easier. I've gotten many complements about it, and it's been working well over the years with few hiccups.

The database file is hosted on a dedicated server that I administer, which the lab uses for file storage. This means that multiple people could be accessing the database on different computers at the same time. The app must consider the possibility of another user on another machine updating the database while the app is open. To do this, I designed the app to monitor the database file for changes. When a change occurs, it reloads the information from the database so that the user always sees the most recent information on the screen.

About a year ago, I started researching a replacement for our file server. It was over 5 years old and out of warranty, and its version of Windows (Windows Server 2008) was fast approaching end-of-life. Because we mainly used it for file storage, I recommended we get a Linux-based NAS device because they are cheaper than a full-blown Windows server.

The two major competitors in the NAS space are QNAP and Synology. I decided to go with QNAP because they offered a model that came with more RAM and an HDMI port (most NAS devices do not come with any video ports). My reasoning was that the HDMI port would allow me to administer the device just like a normal server if the network ever went down.

The library purchased it a few months ago, and I deployed it last week. It has been working well so far, but one hiccup I've encountered is that, ever since I deployed it, the class registration app I wrote has been slow to detect updates to the database file. Like, really slow. About 10 seconds slow.

I ran some tests and found that when my app updated the database, the "date modified" timestamp of the database file was slow to update. This was why my app was taking so long to detect any changes to it. But when I wrote a test program that just saved some content to a text file on the file server, the text file's timestamp would update immediately. Why, then, was the Access file behaving differently?

I thought that maybe the open-source library my app uses to interface with the Access database, called "Jackcess", was doing something different under the hood. I started a thread on their support forum and learned that they use Java's "RandomAccessFile" class to write to the database. This class allows you to update small sections of a file individually instead of re-writing an entire file from scratch, which is how most computer programs deal with updating files.

So, it looks like the culprit here is the new Linux-based NAS server. It seems to handle these kind of file updates differently than the old Windows server did. The simplest workaround I can think of would be to create some kind of dummy file and monitor that for changes instead of the database. The app would then update the dummy file whenever it makes a change to the database, which would cause the dummy file's "date modified" timestamp to update, signaling to other computers on the network that the database was just changed. That should hopefully get things back to normal!

Monday, June 3, 2019

Windows Tips 'n Tricks

I stumbled upon a thread on the r/sysadmin board with tons of great Windows tips. Here is a list of the ones I found the most interesting:

File Explorer to cmd
Open File Explorer and navigate to any directory. Click into the address bar, type "cmd", and press Enter. A command prompt window will open at that location (source).

cmd to File Explorer
Conversely, open a command prompt window and type "start .". A File Explorer window will open to whatever your current directory is (source).

cmd and F7
Press F7 at a command prompt to display a selectable command history. It doesn't work well for really long commands, but for shorter ones it works great (source).

Copy as path
In File Explorer, hold Shift while right-clicking a file. This makes a "Copy as path" option available on the context menu. Clicking this will copy the file's absolute path to the clipboard (source).

Copy text in dialog boxes
It is possible to copy the text in a dialog box, even if you can't highlight it! This is great for extracting error messages so you can Google them. Simply click on the dialog box to make sure it has focus, then press Ctrl+C. In my testing, this didn't work with Microsoft Office dialog boxes, so it may not work everywhere (source).

For example, below is the pasted content from a Notepad dialog box.
[Window Title]

[Main Instruction]
Do you want to save changes to Untitled?

[Save] [Don't Save] [Cancel]
Screenshots of windows
If you're not using any third-party screenshot tools, pressing Alt+PrtScn copies a screenshot of the currently active window to the clipboard. No more having to crop full-screen screenshots with Paint (source)!

And here are a couple tips of my own:

Desktop keyboard shortcuts
It's possible to assign keyboard shortcuts to desktop icons. Right-click on the icon and click "Properties". Click into the "Shortcut key" field and type a letter. The shortcut will now be Ctrl+Alt+whatever letter you typed.

Show Desktop
I use this one all the time. Pressing Win+D hides all of your windows so you can see the desktop. Useful!

Emoji keyboard
Last but not least: While inside a textbox, pressing Win+. (Windows key + period key) to open an emoji keyboard.