Web Development

DNS Troubleshooting

DNS troubleshooting is actually a bit of fun (maybe) and I had to do some of it recently for spectrumautomation.com.au. The end of the story was that the authority records were pointing to the completely wrong place. Although it was fairly easy to see, proving it was the difficult part. So here are some tools I found useful.

nslookup

One of the simplest tools out there. Does as its name suggests, DNS lookups.

dig

dig lets you grab a whole heap of DNS information, basically the entire DNS response from any server that you want. It's extremely useful to track down the DNS lookup process by basically iterating down from the root server all the way to the final authoritative servers.

dnstracer

A cool tool to automatically perform a similar trace as to what can be done by dig, a good way of getting an overall view of how the DNS system is arranged.

DNS Bajaj

DNS Bajaj generates a diagram showing the delegation and connection between the DNS servers for a domain, all the way down from the top level domain.

DNSStuff.com

DNSStuff.com has a very useful DNS report tool which will give you a wide range of information regarding the DNS information for your domain including failures and warnings with respect to RFCs. They also provide web access to standard tools such as ping, traceroute, dig and whois, although the tools are useful only for a certain amount of tests. I used DNSStuff.com as another test point to avoid caching issues.

Automated Source Code Processing

There's a tool called PMD that lets you do all sorts of nifty things to java code, looking for possible bugs, dead code, suboptimal code and overcomplicated expressions. Unfortunately (or fortunately), I don't code in Java, but there is an additional tool in the set, CPD which let's you find duplicate code sections.

Duplicate code sections are bad, because if you copy and paste something, and there's a bug, then you've copied the bug which might get missed in a bugfix. But all seasoned coders know such things. I always remember the phrase "Code duplication is an error.", and sometimes I even pay attention to it ;-).

The good thing about CPD is it works with C, C++, Java, JSP and PHP, so it should be a worthy tool to add to a programmers collection.

Pagination - The Definitive Guide

Pagination - EASY you say: just use LIMIT, OFFSET syntax. But what happens if I want a paginated list of Authors with a list of Books by each Author next to it?

 SELECT author_name,book_title FROM author INNER JOIN book USING(author_id) LIMIT 10; 

Now imagine that you have 5 Authors in your database each with 20 books. That query will return 10 rows, all with the same Author in them.

So how do you paginate such a query, and hence any joined query? It's a matter of using 3 separate queries (2 if the RDBMS you are using supports LIMIT,OFFSET syntax in subselects).

SELECT count(author_id) AS total FROM author 
    INNER JOIN book USING(author_id);
id_list = SELECT author_id FROM author LIMIT 10;
SELECT author_name,book_title FROM author INNER JOIN 
    book USING(author_id) WHERE author_id IN(id_list)

If your RDBMS supports LIMIT,OFFSET syntax in subselects, then steps 2 and 3 can be done with:

SELECT author_name,book_title FROM author 
    INNER JOIN book USING(author_id) WHERE author_id 
    IN SELECT author_id FROM author LIMIT 10;

You can then use whatever programming language you like to go to a page number like this (example in PHP):

$num_pages = floor($count/$num_per_page);
if($count%$num_per_page)
    $num_pages++;
if($num>$num_pages)
    throw new Exception('Page: '.$num.' does not exist!');
$start = (($num-1)*$num_per_page); 

Then use $start as the OFFSET and $num_per_page as the LIMIT Happy paginating!

Syndicate content