The possibility to end the contract before it expires depends on the type of contract. If the contract is for 3 years or less, your landlord can’t end the contract before it expires. It can be ended at the expiry date, when the landlord gives you a 3 month notice.
A 9-year contract can be ended by the landlord, but a 6 month notice must be given.