How do I do that exactly? What should be done to have long-lasting supply of food?

I had a castle but when I was besieged, it only lasted for two years. Then I was fighting Turks and they only had a keep or something but it "won't fall without direct assault."

What's going on? I always improve my agriculture (I'm guessing that counts).